SAT / PSAT
SAT / PSAT Prep
History & Social Science
AP World History AP US History AP European History AP Human Geography AP US Government & Politics AP Psychology AP Macroeconomics AP Microeconomics
English
AP English Language & Composition AP English Literature & Composition
Math & Computer Science
AP Calculus AB/BC AP Precalculus AP Statistics AP Computer Science A AP Computer Science Principles
Sciences
AP Biology AP Chemistry AP Environmental Science AP Physics 1 AP Physics 2
World Languages & Arts
AP Spanish Language AP Art History AP Music Theory Start studying →
Unit 3 · Algorithms & Programming Flashcards Cheat Sheet Essentials Visual Review MC Practice FRQ Practice

AP Computer Science Principles Unit 3 Visual Review

A topic-by-topic visual walkthrough of Big Idea 3: Algorithms and Programming — variables, math, strings, Booleans, conditionals, iteration, lists, procedures, libraries, simulations, and efficiency.

← Back to Unit 3 hub
TOPIC 3.1 Variables and Assignments ◊ AP CSP pseudocode — the arrow ← means "assign" score 100 stores 100 in score score score + 1 reads old value, adds 1 A variable names a value A variable is a named location that holds a value you can read and change. Assignment evaluates the RIGHT side, then stores it in the LEFT variable. Input & output n ← INPUT() gets a value from the user DISPLAY(n) shows the value, followed by a space a ← expression assigns the evaluated right side into the variable a. The Review Hub · AP Computer Science Principles · Big Idea 3 TOPIC 3.2 Data Abstraction Manage complexity with abstraction A variable is a simple abstraction — one name that stands for a value. A LIST bundles MANY values under one name so you don't need dozens of separate variables. Why it helps Abstraction lets you focus on WHAT data represents, not how it's stored. A clear name (like temperatures) makes a program easier to read and change. Lists let one algorithm work on any amount of data. // one list holds all the scores instead of score1, score2, score3... scores [88, 92, 75, 100] Data abstraction (variables & lists) hides detail and manages complexity. The Review Hub · AP Computer Science Principles · Big Idea 3 TOPIC 3.3 Mathematical Expressions // arithmetic operators + - * / a MOD b remainder of a ÷ b 17 / 5 → 3.4 17 MOD 5 → 2 // order of operations applies MOD is everywhere on the exam n MOD 2 = 0 → n is EVEN. n MOD 2 = 1 → n is ODD. MOD wraps values around a range (clock arithmetic, cycling colors). MOD shares precedence with * and /. Expressions produce a single value An expression combines values, variables, and operators, and evaluates to ONE result you can store or display. Know MOD (remainder): n MOD 2 tests even/odd; 17 MOD 5 = 2. The Review Hub · AP Computer Science Principles · Big Idea 3 TOPIC 3.4 Strings A string is ordered text A sequence of characters, such as a word or a sentence. CONCATENATION joins strings together end to end. LENGTH gives the number of characters. // building a greeting name "Ada" msg "Hi, " + name DISPLAY(msg) → Hi, Ada LEN("Ada") = 3 Substrings & procedures Different languages use different string procedures (substring, position, length). On the exam, read the given procedure descriptions. A string is ordered text; concatenation (+) joins strings together. The Review Hub · AP Computer Science Principles · Big Idea 3 TOPIC 3.5 Boolean Expressions TRUTH TABLE ABA AND BA OR B TTTT TFFT FTFT FFFF AND · OR · NOT A Boolean expression evaluates to true or false. AND: true only if BOTH are true. OR: true if AT LEAST ONE is true. NOT: flips true ↔ false. Relational ops: = ≠ > < ≥ ≤ Boolean expressions use AND, OR, NOT and relational operators to give true/false. The Review Hub · AP Computer Science Principles · Big Idea 3 TOPIC 3.6 Conditionals IF (age ≥ 18) { DISPLAY("Adult") } ELSE { DISPLAY("Minor") } Selection chooses a path IF runs its block only when the condition is true. ELSE gives the alternative path when the condition is false. Exactly one of the two blocks runs. Conditionals create branching Different inputs lead the program down different paths — the basis of decision-making in every algorithm. IF runs when true; ELSE runs when false — selection chooses a path. The Review Hub · AP Computer Science Principles · Big Idea 3 TOPIC 3.7 Nested Conditionals IF (score ≥ 90) { grade ← "A" } ELSE { IF (score ≥ 80) { grade ← "B" } ELSE { grade ← "C" } } Conditionals inside conditionals A conditional placed inside another lets you choose among MANY options. The inner IF is only reached when the outer condition already decided a path. Order the conditions carefully so the right branch is chosen. Nested conditionals select among many options — order the conditions with care. The Review Hub · AP Computer Science Principles · Big Idea 3 TOPIC 3.8 Iteration // repeat a fixed number of times REPEAT 5 TIMES { DISPLAY("Hi") } // repeat until a condition holds REPEAT UNTIL (x = 0) { ... } Two kinds of loops REPEAT n TIMES: runs exactly n times. REPEAT UNTIL: runs until the condition becomes true. If the condition never becomes true → infinite loop. Iteration avoids repeating yourself A loop repeats a block of statements, so one short piece of code can process many items or run many times. REPEAT UNTIL checks its condition before each pass — make sure the loop moves toward stopping. REPEAT n TIMES counts; REPEAT UNTIL loops until a condition is true. The Review Hub · AP Computer Science Principles · Big Idea 3 TOPIC 3.9 Developing Algorithms An algorithm is a clear recipe A finite sequence of steps that solves a problem or accomplishes a task. Built from the three building blocks: SEQUENCING, SELECTION, ITERATION. Different algorithms can solve the same problem. Comparing algorithms Two algorithms are EQUIVALENT if they always produce the same result. Choose based on clarity, speed, and how well they handle edge cases. Plan with pseudocode or a flowchart first. Combine the building blocks Most algorithms mix sequencing, selection, and iteration — e.g. loop through a list and use an IF to act on each item. Algorithms combine sequencing, selection, and iteration to solve a problem. The Review Hub · AP Computer Science Principles · Big Idea 3 TOPIC 3.10 Lists nums ← [12, 5, 8, 20] AP CSP lists start at index 1 121 52 83 204 nums[1] → 12 LENGTH(nums) → 4 // list procedures APPEND(nums, 7) add to end INSERT(nums, 2, 9) at index 2 REMOVE(nums, 3) delete index 3 LENGTH(nums) size of list Traverse with FOR EACH FOR EACH n IN nums { sum ← sum + n } Visits every element in order — great for sum, count, min/max, and search. AP CSP lists are 1-indexed; traverse with FOR EACH, size with LENGTH. The Review Hub · AP Computer Science Principles · Big Idea 3 TOPIC 3.11 Binary Search Halve the search each step Check the MIDDLE element. If it's the target, done. If the target is smaller, search the LEFT half; if larger, the RIGHT. REQUIRES the list to be SORTED first. Much faster than linear Each step throws away HALF the remaining items. 1,000 items → about 10 checks; 1,000,000 → about 20 checks. Search space halves each step: 16 8 4 2 1 16 → 8 → 4 → 2 → 1: found in ~4 steps instead of up to 16. Binary search halves a SORTED list each step — far faster than checking one by one. The Review Hub · AP Computer Science Principles · Big Idea 3 TOPIC 3.12 Calling Procedures resultmax(8, 3) // call max with arguments 8 and 3 return value procedure name arguments A procedure = a named block Also called a method or function. CALLING it runs its code. ARGUMENTS are the values you pass in; they fill the procedure's PARAMETERS. Return values A procedure may RETURN a value that you store or use in an expression. You can call a procedure without knowing how it works inside — that's abstraction. Calling a procedure runs its code with the arguments you pass in. The Review Hub · AP Computer Science Principles · Big Idea 3 TOPIC 3.13 Developing Procedures PROCEDURE area(w, h) { a ← w * h RETURN (a) } DISPLAY(area(4, 5)) → 20 Procedural abstraction Writing a procedure lets you name a task and reuse it — no copy-pasting code. Benefits: less repetition, easier to read, test, and fix in ONE place. PARAMETERS generalize it to work on many inputs. Writing procedures with parameters reduces repetition and manages complexity. The Review Hub · AP Computer Science Principles · Big Idea 3 TOPIC 3.14 Libraries Reuse code others wrote A LIBRARY is a collection of procedures you can use in your own program. An API describes each procedure's behavior, inputs, and outputs. Why use libraries? • Save time — don't reinvent the wheel. • Use tested, reliable code. • Focus on YOUR program's unique logic. You call library procedures without seeing inside. Abstraction at a larger scale Libraries are procedural abstraction taken further: a whole toolbox of ready-made procedures behind simple names. Reading the documentation tells you how to call each one — what to pass and what you get back. A library is reusable procedures; its API documents how to call them. The Review Hub · AP Computer Science Principles · Big Idea 3 TOPIC 3.15 Random Values RANDOM(1, 6) // returns 1, 2, 3, 4, 5, or 6 — each equally likely // RANDOM(a, b) includes BOTH endpoints a and b Generating randomness RANDOM(a, b) returns a random integer from a to b, inclusive. Used for games, shuffling, sampling, and simulations. Every value in the range is equally likely. Different runs, different output A program using RANDOM can produce a DIFFERENT result each time it runs. This adds unpredictability and variety — but makes testing harder to reproduce. Great for games; central to simulations (3.16). RANDOM(a, b) returns an equally-likely integer from a to b, inclusive. The Review Hub · AP Computer Science Principles · Big Idea 3 TOPIC 3.16 Simulations A model of the real world A simulation is a program that models a real phenomenon to study it. It SIMPLIFIES reality — it can't include every detail, so it makes assumptions. Random values give realistic variation. Why simulate? Simulations are useful when the real thing is too costly, slow, dangerous, or impossible to test directly. Examples: weather, crash tests, disease spread, rolling dice thousands of times. Results guide decisions — but a model is not reality A simulation's accuracy depends on its assumptions. Better models give better predictions, but always simplify. A simulation models reality with simplifying assumptions — safer and cheaper than the real thing. The Review Hub · AP Computer Science Principles · Big Idea 3 TOPIC 3.17 Algorithmic Efficiency Efficiency = work vs. input size Efficiency estimates how the number of steps grows as the input grows. REASONABLE time: steps grow like a polynomial (n, n², n³ …). UNREASONABLE: grows exponentially (2ⁿ). Faster approaches Binary search (halving) beats linear search (one by one). A HEURISTIC gives a good-enough answer quickly when the exact one is too slow. Fewer nested loops usually means faster. Reasonable vs. unreasonable time Some problems can be solved in reasonable time; others (exponential) become impractical as input grows large. Reasonable time grows polynomially; exponential growth becomes impractical — heuristics help. The Review Hub · AP Computer Science Principles · Big Idea 3 TOPIC 3.18 Undecidable Problems Some problems cannot be solved by ANY algorithm An UNDECIDABLE problem is one for which no algorithm can give a correct yes/no answer for EVERY possible input. This is a fundamental LIMIT of computation — not just a matter of needing a faster computer. Decidable vs. undecidable DECIDABLE: an algorithm always gives the correct answer (e.g. "is n even?"). UNDECIDABLE: no algorithm can work for all inputs. Not the same as "hard" Undecidable ≠ slow or difficult. A slow problem still HAS a solution; an undecidable one provably does not. There is no general "will this program halt?" test. An undecidable problem has no algorithm that solves it correctly for every input. The Review Hub · AP Computer Science Principles · Big Idea 3
1 / 18

How to use the visual review

Spend 30 seconds per slide before clicking next. Look at the diagram, then ask yourself: "Could I trace this code, or explain this construct, from memory?"

Use the fullscreen button () on desktop for the best experience. Use arrow keys to navigate. Tap "Show all slides" to jump around.

This is great for review the night before the exam — fast, visual, and covers every construct you need to recognize in Unit 3.