Variables and Assignments
Variables hold one value at a time. The left-arrow operator assigns a value. The stored value is always the most recent assignment. Data types include numbers, Booleans, strings, and lists.
An algorithm is a finite set of instructions that accomplishes a task. Programs implement algorithms using sequencing (steps in order), selection (conditionals), and iteration (loops). Abstraction, through named variables, lists, and procedures, manages complexity so programs stay readable and reusable.
Fiveable's AP Computer Science Principles Unit 3 review covers 19 topics, with guided practice questions for the unit.
Variables hold one value at a time. The left-arrow operator assigns a value. The stored value is always the most recent assignment. Data types include numbers, Booleans, strings, and lists.
Lists are ordered sequences indexed from 1. Data abstraction names a collection so programs work with the group rather than individual storage details, reducing complexity.
Algorithms use sequencing, selection, and iteration. Arithmetic operators include +, -, *, /, and MOD. Standard order of operations applies; MOD has the same precedence as * and /.
String concatenation joins strings end-to-end. A substring is a portion of an existing string. Strings are ordered sequences of characters.
Boolean values are true or false. Relational operators (=, not-equal, <, >, <=, >=) compare values. Logical operators NOT, AND, and OR combine Boolean expressions.
IF and IF/ELSE statements execute different blocks based on whether a Boolean condition is true or false. Selection determines which part of an algorithm runs.
Nested conditionals place one IF inside another. The inner condition is only evaluated when the outer condition is true. Tracing all paths is essential.
REPEAT n TIMES runs a block exactly n times. REPEAT UNTIL(condition) repeats until the condition is true, checking before each pass. An infinite loop occurs when the condition never becomes true.
Algorithms can be created, combined, or modified. Two algorithms are equivalent if they always produce the same result. Common building blocks include max/min, sum/average, divisibility checks, and maze traversal.
List operations include indexing (aList[i]), INSERT, APPEND, REMOVE, and LENGTH. FOR EACH traversal visits every element. Linear search checks elements one by one.
Binary search requires sorted data. It checks the middle element and eliminates half the remaining data each step, making it more efficient than linear search on large sorted data sets.
A procedure call passes arguments to parameters, executes the body, and returns control to the call site. A RETURN statement sends a value back and ends the procedure.
Procedural abstraction names a process so callers only need to know inputs and outputs. Modularity divides a program into subprograms. Parameters generalize procedures for reuse.
A library is a collection of pre-written procedures. An API specifies how those procedures behave. Documentation is necessary to use a library correctly.
RANDOM(a, b) returns an integer from a to b inclusive, with each value equally likely. Programs using RANDOM may produce different results on each execution.
Simulations are abstractions of real-world phenomena. They use changing values to model behavior, allow investigation without real-world constraints, and can contain bias from inclusion or exclusion choices.
Polynomial-time algorithms run in reasonable time. Exponential and factorial algorithms run in unreasonable time. Heuristics provide approximate solutions when exact solutions are impractical.
A decidable problem always has an algorithmic yes/no solution. An undecidable problem has no algorithm that works correctly for all inputs, though some specific instances may still be solvable.
Big Idea 3 is 30-35% of the AP Computer Science Principles exam. Review all 18 topics: variables, conditionals, loops, lists, procedures, and efficiency.
Try AP-style questions on unit 3, then use the review notes below for anything you miss.
A timed, AP-style test built only from unit 3 questions — multiple choice plus free response, scored with AI feedback. Use the standard format or build your own.
A variable is an abstraction that holds one value at a time. The AP exam reference sheet uses the left-arrow operator (a <- expression) to assign a value. The value stored is always the most recent assignment. Meaningful variable names improve readability.
Trace this sequence: a <- 3, b <- a, a <- 10. What does b hold? Answer: 3, because b was assigned a copy of a before a changed.
A list is an ordered sequence of elements, each identified by an index starting at 1 on the AP exam. Data abstraction gives a collection a single name, hiding the details of how individual elements are stored. This makes programs easier to build and maintain.
If myList = [10, 20, 30], what is myList[2]? Answer: 20, because AP pseudocode uses 1-based indexing.
An expression evaluates to a single value. Arithmetic expressions use +, -, *, /, and MOD. MOD returns the remainder and has the same precedence as * and /. String concatenation joins two strings end-to-end. A substring is a portion of an existing string.
What does (14 MOD 4) + 1 evaluate to? Step through: 14 MOD 4 = 2, then 2 + 1 = 3.
A Boolean value is either true or false. Relational operators compare two values and produce a Boolean. Logical operators combine Boolean values. The AP reference sheet provides NOT, AND, and OR.
Evaluate: (3 > 2) AND (5 = 6). The first condition is true, the second is false. AND requires both to be true, so the result is false.
| Operator | Returns true when |
|---|---|
| NOT condition | condition is false |
| condition1 AND condition2 | both conditions are true |
| condition1 OR condition2 | at least one condition is true |
Selection uses IF and IF/ELSE statements to execute different code blocks based on a Boolean condition. Nested conditionals place one IF inside another, allowing more specific branching. Tracing every possible path is the key exam skill.
An IF checks x > 0. Inside that block, another IF checks x > 10. If x = 5, which blocks execute? The outer block runs (5 > 0 is true), but the inner block does not (5 > 10 is false).
Iteration repeats a block of statements. REPEAT n TIMES runs the block exactly n times. REPEAT UNTIL(condition) runs the block until the condition becomes true, checking the condition before each iteration. If the condition is true at the start, the block never runs.
A REPEAT UNTIL(x >= 5) loop starts with x = 5. How many times does the body run? Zero times, because the condition is already true before the first iteration.
Algorithms can be created from scratch, by combining existing algorithms, or by modifying them. Two algorithms that look different can produce the same result. Some conditional statements can be rewritten as equivalent Boolean expressions and vice versa. Knowing common building-block algorithms speeds up development.
Two algorithms both find the maximum of two numbers but use different conditional structures. Are they equivalent? Yes, if they return the same value for every possible pair of inputs.
The AP reference sheet provides specific list operations. Indexing starts at 1. INSERT shifts elements right and increases length. REMOVE shifts elements left and decreases length. APPEND adds to the end. FOR EACH traversal visits every element in order.
After INSERT(myList, 2, 99) on [10, 20, 30], what is myList? Answer: [10, 99, 20, 30]. The value 99 is placed at index 2 and the original elements shift right.
Binary search finds a value in a sorted data set by checking the middle element, then eliminating the half that cannot contain the target, and repeating. It requires sorted data and is more efficient than linear search for large data sets.
A sorted list has 16 elements. In the worst case, how many times does binary search check the middle before concluding the value is absent? At most 4 times, because 16 halves to 8, 4, 2, 1.
| Search type | Data requirement | Relative efficiency on large sorted data |
|---|---|---|
| Linear (sequential) search | None; works on unsorted data | Slower; checks up to every element |
| Binary search | Data must be sorted | Faster; eliminates half the remaining elements each step |
A procedure is a named group of instructions with optional parameters and a return value. Calling a procedure passes arguments to its parameters, executes the body, and returns control to the call site. Procedural abstraction lets you use a procedure by knowing what it does, not how it works internally. Modularity breaks a program into subprograms, each solving one part of the problem.
A procedure square(n) returns n * n. The call result <- square(4) runs the procedure with n = 4 and stores 16 in result. What is result? 16.
A software library is a collection of pre-written procedures available for use in new programs. An API specifies how those procedures behave and how to call them. Documentation is required to understand what a library provides and how to use it correctly.
Why is API documentation necessary even when a library is available? Because the API specification tells you what arguments to pass and what the procedure returns; without it, you cannot call the procedure correctly.
RANDOM(a, b) returns a random integer from a to b, inclusive. Each integer in the range is equally likely. Because the result varies each run, programs using RANDOM can produce different outputs on different executions.
RANDOM(3, 7) is called. List all possible results. Answer: 3, 4, 5, 6, 7. Each is equally likely.
A simulation is an abstraction of a real-world object or phenomenon built for a specific purpose. It uses changing values to model a system's behavior, allowing investigation without the cost, danger, or scale of the real event. Simulations simplify reality and can introduce bias based on what is included or excluded.
A simulation of car crash safety tests is run instead of using real cars. What is one advantage and one limitation? Advantage: no physical risk or cost. Limitation: the simulation may not capture every real-world variable, introducing bias.
Efficiency measures how many computational resources an algorithm uses as input size grows. Algorithms that run in polynomial time (constant, linear, quadratic) are considered to run in reasonable time. Algorithms with exponential or factorial growth run in unreasonable time and become impractical for large inputs. Heuristics provide approximate solutions when exact solutions would take too long.
An algorithm doubles its steps every time one element is added to the input. Is this reasonable or unreasonable time? Unreasonable, because doubling per element is exponential growth.
| Efficiency type | Growth pattern | Practical for large inputs? |
|---|---|---|
| Constant | Same steps regardless of input size | Yes |
| Linear | Steps grow proportionally with input size | Yes |
| Polynomial (quadratic, cubic) | Steps grow as a power of input size | Generally yes |
| Exponential | Steps double (or more) with each added input element | No |
| Factorial | Steps grow as n! of input size | No |
A decidable problem is one for which an algorithm can always produce a correct yes or no answer for every input. An undecidable problem is one for which no such algorithm exists. Some specific instances of an undecidable problem may still be solvable, but no single algorithm handles all instances correctly.
Is 'Is this number divisible by 3?' decidable or undecidable? Decidable, because an algorithm using MOD can always give the correct answer for any integer input.
| Problem type | Algorithm always correct? | Example |
|---|---|---|
| Decidable | Yes, for all inputs | Is the number even? (use MOD 2) |
| Undecidable | No algorithm works for all inputs | Halting problem: does this program stop for this input? |
| Term | Definition |
|---|---|
| Algorithm | A finite set of instructions that accomplishes a specific task. Every algorithm can be built from sequencing, selection, and iteration. |
| Variable | A named abstraction in a program that holds one value at a time. The stored value is always the most recent assignment. |
| Sequencing | Executing code statements in the order they appear, top to bottom, with each step completing before the next begins. |
| Selection | Using IF or IF/ELSE statements to execute different blocks of code based on whether a Boolean condition is true or false. |
| Conditional Statements | IF and IF/ELSE blocks that branch program execution based on a Boolean expression. Nested conditionals place one inside another. |
| REPEAT UNTIL(condition) | An iteration statement that repeats a block until the condition evaluates to true. If the condition is true initially, the block runs zero times. |
| Procedural Abstraction | Naming a process in a procedure so callers know what it does without needing to know how it works internally. Enables code reuse and modularity. |
| Parameters | Input variables listed in a procedure definition. They receive copies of the arguments passed when the procedure is called. |
| modulus operator | a MOD b returns the remainder when a is divided by b. Example: 17 MOD 5 = 2. Used for divisibility checks and cycling through values. |
| Linear Search | Checks each element in a list one by one until the target is found or the list ends. Works on unsorted data. |
| RANDOM(a, b) | Returns a random integer from a to b inclusive, with each value equally likely. Programs using it may produce different results each run. |
| Heuristic | An approach that finds a good-enough approximate solution when finding the exact optimal solution would require unreasonable time. |
| Decidable Problem | A decision problem for which an algorithm can always produce a correct yes or no answer for every possible input. |
| reasonable time | Algorithms with polynomial efficiency or lower that remain practical as input size increases. |
| Library | A collection of pre-written procedures that can be used in new programs. An API specifies how those procedures behave; documentation explains how to use them. |
Miss rates come from Fiveable multiple-choice practice.
AP pseudocode lists start at index 1, not 0. Writing aList[0] to access the first element is incorrect on the exam. Always use aList[1] for the first element.
REPEAT UNTIL stops when the condition is true, not false. Students often reverse the logic. If the condition is already true before the loop, the body runs zero times.
After b <- a and then a <- 10, b still holds the original value of a. Changing a later does not change b because assignment is a copy, not a link.
Parameters are the variable names in the procedure definition. Arguments are the actual values passed in the call. Mixing up which is which leads to errors when tracing procedure calls.
Binary search only works on sorted data. Applying it to an unsorted list can produce a wrong answer or miss the target entirely. Always check the sorted requirement first.
A large portion of AP CSP multiple-choice questions present a pseudocode segment and ask what value a variable holds, what the output is, or how many times a loop runs. The skill is substituting specific values and following every assignment, conditional branch, and iteration step by step using the AP reference sheet notation.
Questions ask students to explain why a list or procedure makes a program easier to develop or maintain. Strong responses name the specific abstraction (list, procedure, library), describe what detail it hides, and connect it to reducing code duplication or making the program easier to modify.
The exam asks students to compare two algorithms for equivalence or efficiency, identify whether binary search or linear search is appropriate for a given scenario, classify an algorithm as running in reasonable or unreasonable time, and recognize that some problems are undecidable. These questions require applying definitions precisely rather than recalling general descriptions.
Open the individual guides for Unit 3 when you want a closer review of one topic.
Use AP-style practice after you review the notes so you can check what you understand.
Practice free-response reasoning and compare your answer with scoring guidance.
Watch past review streams filtered to Unit 3 when you want a video walkthrough.
Open the Fiveable one-page unit review, then explore visual cheatsheets for a quick refresher.
Estimate your broader AP score goal after you review the course and exam format.

Print the unit cheatsheets ($3) for Unit 3. Yours to keep, no subscription needed.
get printablesThe AP CSP Unit 3 progress check includes both MCQ and FRQ parts drawn from the unit's 18 topics. The MCQ section tests concepts like Boolean expressions, conditionals, iteration, lists, and binary search. The FRQ part typically asks you to trace or write code segments involving procedures, variables, and algorithms. The progress check is College Board's built-in checkpoint in AP Classroom, so it closely mirrors the language and format of the actual AP exam. Topics like Developing Algorithms (3.9), Calling Procedures (3.12), and Algorithmic Efficiency (3.17) are especially common targets. Practicing with matched questions at /ap-comp-sci-p/unit-3 is a solid way to prepare before you take the progress check.
AP CSP Unit 3 FRQs most often pull from topics like Developing Procedures (3.13), Developing Algorithms (3.9), Lists (3.10), and Simulations (3.16). These questions ask you to write or trace code, explain what a procedure does, or describe how an algorithm handles specific inputs. To practice effectively, try writing short code segments by hand for each of those topics, then explain your logic out loud as if you're answering a written-response prompt. Focus on being precise about sequencing, selection, and iteration since graders look for correct use of those structures. You can find FRQ-style practice questions at /ap-comp-sci-p/unit-3.
You can find AP CSP Unit 3 multiple-choice and practice test questions at /ap-comp-sci-p/unit-3. That page has resources covering all 18 topics in the unit, from Variables and Boolean Expressions to Binary Search and Undecidable Problems. For the best MCQ prep, look for questions that test conditionals, iteration, and list operations since those show up most on the exam. Mixing topic-specific practice with full unit practice tests helps you spot which concepts still need work before exam day.
Start AP CSP Unit 3 by building a strong foundation in variables, expressions, and Boolean logic before moving to conditionals and iteration, since every later topic depends on those. Then work through lists, procedures, and algorithms in order, writing small code examples for each concept rather than just reading about them. Here's a practical study approach: - Trace code by hand. For topics like Binary Search (3.11) and Nested Conditionals (3.7), manually step through examples to see exactly what happens at each line.
- Write your own procedures. Developing Procedures (3.13) and Developing Algorithms (3.9) are high-value topics. Writing short programs from scratch builds the skill faster than reviewing notes.
- Connect simulations to randomness. Topics 3.15 and 3.16 (Random Values and Simulations) are often tested together, so study them as a pair.
- Tackle efficiency and limits last. Algorithmic Efficiency (3.17) and Undecidable Problems (3.18) are conceptual, so save them for after you're comfortable with the coding topics. Visit /ap-comp-sci-p/unit-3 for topic guides and practice questions to check your understanding along the way.