---
title: "AP CSP Unit 3 Review: Algorithms & Programming Fundamentals"
description: "AP Computer Science Principles Unit 3 covers Variables and Assignments and Data Abstraction. Study guides, practice questions, and key terms for every topic."
canonical: "https://fiveable.me/ap-comp-sci-p/unit-3"
type: "unit"
subject: "AP Computer Science Principles"
unit: "Unit 3 – Algorithms & Programming Fundamentals"
---

# AP CSP Unit 3 Review: Algorithms & Programming Fundamentals

## Overview

Unit 3 covers the full range of programming fundamentals tested on the AP CSP exam. You will work with variables, data types, lists, strings, Boolean expressions, conditionals, iteration, and procedures. The unit also addresses algorithm design, binary search, libraries, random values, simulations, efficiency, and undecidable problems.

## AP CED Alignment

This unit hub is organized around AP Course and Exam Description topics, skills, and exam task types when they are available in the source data.
- 3.1: Variables and Assignments
- 3.2: Data Abstraction
- 3.3: Mathematical Expressions
- 3.4: Strings
- 3.5: Boolean Expressions
- 3.6: Conditionals
- 3.7: Nested Conditionals
- 3.8: Iteration
- 3.9: Developing Algorithms
- 3.10: Lists
- 3.11: Binary Search
- 3.12: Calling Procedures
- 3.13: Developing Procedures
- 3.14: Libraries
- 3.15: Random Values
- 3.16: Simulations
- 3.17: Algorithmic Efficiency
- 3.18: Undecidable Problems
- guide: Big Idea 3: Algorithms and Programming
- 3.2: Data Abstraction and Lists
- 3.3-3.4: Expressions: Arithmetic and Strings
- 3.6-3.7: Conditionals and Nested Conditionals
- 3.10: List Operations and Traversal
- 3.12-3.13: Calling and Developing Procedures
- 3.14: Libraries and APIs
- Practice 4: Code Analysis
- Practice 1: Computational Solution Design
- Practice 3: Abstraction in Program Development

## Topics

- [3.1: Variables and Assignments](/ap-comp-sci-p/unit-3/variables-assignments/study-guide/vtJhAf5XFOkm1uHNDMvh): 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.
- [3.2: Data Abstraction](/ap-comp-sci-p/unit-3/data-abstraction/study-guide/kMMTClSiHohfiaHMGFFE): 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.
- [3.3: Mathematical Expressions](/ap-comp-sci-p/unit-3/mathematical-expressions/study-guide/00lGBdF7QyY5hmd1rubD): Algorithms use sequencing, selection, and iteration. Arithmetic operators include +, -, *, /, and MOD. Standard order of operations applies; MOD has the same precedence as * and /.
- [3.4: Strings](/ap-comp-sci-p/unit-3/strings/study-guide/0bMtDyDHxqMcwyDgQkjw): String concatenation joins strings end-to-end. A substring is a portion of an existing string. Strings are ordered sequences of characters.
- [3.5: Boolean Expressions](/ap-comp-sci-p/unit-3/boolean-expressions/study-guide/LkLTi80KQM04AnmNBxCq): Boolean values are true or false. Relational operators (=, not-equal, <, >, <=, >=) compare values. Logical operators NOT, AND, and OR combine Boolean expressions.
- [3.6: Conditionals](/ap-comp-sci-p/unit-3/conditionals/study-guide/JAgsZEPFqWJchRBqrX1O): 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.
- [3.7: Nested Conditionals](/ap-comp-sci-p/unit-3/nested-conditionals/study-guide/iM5nw43cqaIowgYhEjyD): Nested conditionals place one IF inside another. The inner condition is only evaluated when the outer condition is true. Tracing all paths is essential.
- [3.8: Iteration](/ap-comp-sci-p/unit-3/iteration/study-guide/7megnIMaNHzDdrVKT9mR): 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.
- [3.9: Developing Algorithms](/ap-comp-sci-p/unit-3/developing-algorithms/study-guide/eFTUAVlAEU4XUX3MeQmF): 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.
- [3.10: Lists](/ap-comp-sci-p/unit-3/lists/study-guide/mCE6meIGp5pqs1y5ym3h): List operations include indexing (aList[i]), INSERT, APPEND, REMOVE, and LENGTH. FOR EACH traversal visits every element. Linear search checks elements one by one.
- [3.11: Binary Search](/ap-comp-sci-p/unit-3/binary-search/study-guide/YADShVFQZbqwGicqH3ub): 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.
- [3.12: Calling Procedures](/ap-comp-sci-p/unit-3/calling-procedures/study-guide/lwdr3yhVOtUJZhAmJ5cu): 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.
- [3.13: Developing Procedures](/ap-comp-sci-p/unit-3/developing-procedures/study-guide/Jhzac68HzbAilXRPuZFJ): 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.
- [3.14: Libraries](/ap-comp-sci-p/unit-3/libraries/study-guide/yO78dFsy00yf4OssUKTl): A library is a collection of pre-written procedures. An API specifies how those procedures behave. Documentation is necessary to use a library correctly.
- [3.15: Random Values](/ap-comp-sci-p/unit-3/random-values/study-guide/8SZRS3ELTeNzsvZ3E1OF): 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.
- [3.16: Simulations](/ap-comp-sci-p/unit-3/simulations/study-guide/FbXrprMnzc77nAnIX4rw): 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.
- [3.17: Algorithmic Efficiency](/ap-comp-sci-p/unit-3/algorithmic-efficiency/study-guide/jGSWIqW49BtrQ8dqCWFd): Polynomial-time algorithms run in reasonable time. Exponential and factorial algorithms run in unreasonable time. Heuristics provide approximate solutions when exact solutions are impractical.
- [3.18: Undecidable Problems](/ap-comp-sci-p/unit-3/undecidable-problems/study-guide/q0SSR2ddayx397Hy6ztA): 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.
- [guide: Big Idea 3: Algorithms and Programming](/ap-comp-sci-p/unit-3/review/study-guide/eOWMqAJUdtnmttaCSlis): Big Idea 3 is 30-35% of the AP Computer Science Principles exam. Review all 18 topics: variables, conditionals, loops, lists, procedures, and efficiency.

## Hardest Topics And Analytics

Snapshot: practice snapshot
This snapshot uses Fiveable practice activity to show where students tend to miss questions and which review moves are worth prioritizing first.
- **68% average MCQ accuracy** (Across 27k multiple-choice practice attempts for this unit.)
- **27k MCQ attempts** (Practice activity included in this snapshot.)
- **3.10: Lists**: 46% MCQ miss rate across 3315 attempts. Review Lists with attention to how the concept appears in AP-style source and evidence questions.
- **3.17: Algorithmic Efficiency**: 39% MCQ miss rate across 1674 attempts. Review Algorithmic Efficiency with attention to how the concept appears in AP-style source and evidence questions.
- **3.14: Libraries**: 36% MCQ miss rate across 743 attempts. Review Libraries with attention to how the concept appears in AP-style source and evidence questions.
- **3.1: Variables and Assignments**: 34% MCQ miss rate across 2260 attempts. Review Variables and Assignments with attention to how the concept appears in AP-style source and evidence questions.

## Review Notes

### 3.1: Variables and Assignments

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.

- **Assignment operator**: The left-arrow <- evaluates the expression on the right and stores a copy of the result in the variable on the left.
- **Most-recent-assignment rule**: If a variable is assigned multiple times, its current value is whatever was assigned last. Tracing line by line is the reliable method.
- **Data types**: AP CSP variables can hold numbers, Booleans (true/false), strings, or lists. The type affects what operations make sense on the value.
- **Sequence of assignments**: When b <- a is followed by a <- 2, b still holds the original value of a because assignment copies the value at that moment.

**Checkpoint:** 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.

### 3.2: Data Abstraction and Lists

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.

- **Index**: A natural number that identifies an element's position in a list. The first element is at index 1 in AP pseudocode.
- **Data abstraction**: Naming a collection of values so the program can refer to the group without specifying every element's storage detail.
- **List as a variable**: A list variable holds the entire ordered collection. Assigning one list to another copies the list at that moment.
- **Managing complexity**: Using a list instead of separate variables reduces code length and makes it easier to add, remove, or process related values together.

**Checkpoint:** If myList = [10, 20, 30], what is myList[2]? Answer: 20, because AP pseudocode uses 1-based indexing.

### 3.3-3.4: Expressions: Arithmetic and Strings

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.

- **MOD operator**: a MOD b returns the remainder when a is divided by b. Example: 17 MOD 5 = 2. Useful for checking divisibility and cycling through values.
- **Order of operations**: Standard math precedence applies. MOD, *, and / are evaluated before + and -. Parentheses override default precedence.
- **String concatenation**: Joins two or more strings into one new string placed end-to-end. For example, 'hello' + ' world' produces 'hello world'.
- **Substring**: A part of an existing string extracted by specifying a start and end position.

**Checkpoint:** What does (14 MOD 4) + 1 evaluate to? Step through: 14 MOD 4 = 2, then 2 + 1 = 3.

### 3.5: Boolean Expressions

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.

- **Relational operators**: =, not-equal, <, >, <=, >= compare two values and return true or false.
- **NOT**: Reverses a Boolean: NOT true = false, NOT false = true.
- **AND**: True only when both conditions are true; false otherwise.
- **OR**: True when at least one condition is true; false only when both are false.

**Checkpoint:** 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

### 3.6-3.7: Conditionals and Nested Conditionals

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.

- **IF statement**: Executes a block only when the condition is true; does nothing if the condition is false.
- **IF/ELSE statement**: Executes the first block when the condition is true and the second block when it is false. Exactly one block always runs.
- **Nested conditional**: A conditional statement placed inside another conditional's block. The inner condition is only evaluated if the outer condition is true.
- **Tracing execution paths**: To determine output, substitute specific values and follow which branches execute. Check every branch, not just the first one.

**Checkpoint:** 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).

### 3.8: Iteration

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.

- **REPEAT n TIMES**: Executes the block exactly n times regardless of what happens inside the block.
- **REPEAT UNTIL(condition)**: Checks the condition before each pass. Stops when the condition is true. If true initially, the block runs zero times.
- **Infinite loop**: Occurs in REPEAT UNTIL when the stopping condition can never become true. The program runs forever without terminating.
- **Accumulator pattern**: A variable initialized before the loop that collects a running total, count, or other value updated each iteration.

**Checkpoint:** 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.

### 3.9: Developing Algorithms

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.

- **Algorithm equivalence**: Two algorithms are equivalent if they always produce the same result or side effect for every possible input.
- **Building-block algorithms**: Common patterns include finding a maximum or minimum, computing a sum or average, checking divisibility with MOD, and navigating a robot through a maze.
- **Combining algorithms**: Using a correct existing algorithm as a component of a new one reduces development time and the chance of introducing errors.
- **Conditional-Boolean equivalence**: An IF/ELSE that sets a variable to true or false can often be rewritten as a single Boolean expression assigned directly to that variable.

**Checkpoint:** 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.

### 3.10: List Operations and Traversal

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.

- **aList[i]**: Accesses the element at index i. The first element is aList[1].
- **INSERT(aList, i, value)**: Places value at index i, shifting all elements at index i and beyond one position to the right. List length increases by 1.
- **REMOVE(aList, i)**: Removes the element at index i, shifting all elements after it one position to the left. List length decreases by 1.
- **FOR EACH item IN aList**: Assigns item to each element in order from index 1 to the last index, executing the block once per element.
- **Linear search**: Checks each element one by one until the target is found or the list ends. Works on unsorted data.

**Checkpoint:** 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.

### 3.11: Binary Search

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.

- **Sorted data requirement**: Binary search only works correctly when the data is already sorted. Applying it to unsorted data produces unreliable results.
- **Halving the search space**: Each iteration eliminates half the remaining elements, so the number of steps grows much more slowly than the data set size.
- **Efficiency advantage**: Binary search reaches a result in far fewer steps than linear search when the data set is large and sorted.

**Checkpoint:** 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

### 3.12-3.13: Calling and Developing Procedures

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.

- **Parameters vs arguments**: Parameters are the input variables listed in the procedure definition. Arguments are the actual values passed when the procedure is called.
- **RETURN statement**: Sends a value back to the call site and immediately ends the procedure. The returned value can be stored in a variable.
- **Flow of control**: A procedure call interrupts sequential execution, runs the procedure body, then resumes at the line immediately after the call.
- **Procedural abstraction**: Naming a process so callers only need to know its inputs and outputs, not its internal steps. Enables code reuse and simplifies debugging.
- **Modularity**: Dividing a program into separate procedures, each responsible for one subproblem, so the overall program is easier to read, test, and modify.

**Checkpoint:** 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.

### 3.14: Libraries and APIs

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.

- **Library**: A collection of procedures that can be imported and called in a program without rewriting the underlying code.
- **API**: A specification that defines the inputs, outputs, and behavior of each procedure in a library. It is the contract between the library and the programmer using it.
- **Documentation**: Written descriptions of what each library procedure does, what arguments it accepts, and what it returns. Without documentation, an API cannot be used reliably.
- **Complexity reduction**: Libraries allow programmers to build on existing correct code, reducing the amount of new code that must be written and tested.

**Checkpoint:** 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.

### 3.15: Random Values

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(a, b)**: Generates and returns one integer chosen uniformly at random from a through b, including both endpoints. RANDOM(1, 6) simulates a six-sided die.
- **Inclusive endpoints**: Both a and b are possible results. The total number of possible values is b - a + 1.
- **Non-deterministic output**: A program that calls RANDOM may produce a different result each time it runs, which is useful for simulations, games, and randomized algorithms.

**Checkpoint:** RANDOM(3, 7) is called. List all possible results. Answer: 3, 4, 5, 6, 7. Each is equally likely.

### 3.16: Simulations

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.

- **Simulation as abstraction**: A simulation removes or simplifies real-world details to focus on the aspects relevant to the question being investigated.
- **Simulation bias**: The choices about which real-world elements to include or exclude shape the simulation's results. Leaving out a key factor can make results misleading.
- **When simulations are useful**: Simulations are most valuable when real experiments are too expensive, too dangerous, too slow, too fast, or physically impossible to run.
- **Random values in simulations**: RANDOM is often used inside simulations to model unpredictable real-world variation, such as weather events or population behavior.

**Checkpoint:** 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.

### 3.17: Algorithmic Efficiency

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.

- **Reasonable time**: Polynomial efficiency or lower. The algorithm remains practical as input size increases.
- **Unreasonable time**: Exponential or factorial efficiency. The algorithm becomes impractical very quickly as input size grows even slightly.
- **Heuristic**: An approach that finds a good-enough approximate solution when finding the optimal solution would require unreasonable time.
- **Decision vs optimization problem**: A decision problem asks yes or no (is there a path from A to B?). An optimization problem asks for the best solution (what is the shortest path from A to B?).

**Checkpoint:** 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

### 3.18: Undecidable Problems

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.

- **Decidable problem**: A decision problem where an algorithm can be written that always gives the correct yes or no answer for every possible input. Example: is a number even?
- **Undecidable problem**: A decision problem where no algorithm can always give a correct yes or no answer for every possible input, no matter how the algorithm is designed.
- **Instance-specific solvability**: An undecidable problem may have some inputs for which an algorithm gives the right answer, but there is no algorithm that works correctly for all inputs.

**Checkpoint:** 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?

## Study Guides

- [3.3 Mathematical Expressions](/ap-comp-sci-p/unit-3/mathematical-expressions/study-guide/00lGBdF7QyY5hmd1rubD)
- [3.8 Iteration](/ap-comp-sci-p/unit-3/iteration/study-guide/7megnIMaNHzDdrVKT9mR)
- [3.6 Conditionals](/ap-comp-sci-p/unit-3/conditionals/study-guide/JAgsZEPFqWJchRBqrX1O)
- [3.13 Developing Procedures](/ap-comp-sci-p/unit-3/developing-procedures/study-guide/Jhzac68HzbAilXRPuZFJ)
- [3.9 Developing Algorithms](/ap-comp-sci-p/unit-3/developing-algorithms/study-guide/eFTUAVlAEU4XUX3MeQmF)
- [3.2 Data Abstraction](/ap-comp-sci-p/unit-3/data-abstraction/study-guide/kMMTClSiHohfiaHMGFFE)
- [3.12 Calling Procedures](/ap-comp-sci-p/unit-3/calling-procedures/study-guide/lwdr3yhVOtUJZhAmJ5cu)
- [3.14 Libraries](/ap-comp-sci-p/unit-3/libraries/study-guide/yO78dFsy00yf4OssUKTl)
- [3.4 Strings](/ap-comp-sci-p/unit-3/strings/study-guide/0bMtDyDHxqMcwyDgQkjw)
- [3.15 Random Values](/ap-comp-sci-p/unit-3/random-values/study-guide/8SZRS3ELTeNzsvZ3E1OF)
- [3.16 Simulations](/ap-comp-sci-p/unit-3/simulations/study-guide/FbXrprMnzc77nAnIX4rw)
- [3.5 Boolean Expressions](/ap-comp-sci-p/unit-3/boolean-expressions/study-guide/LkLTi80KQM04AnmNBxCq)
- [3.11 Binary Search](/ap-comp-sci-p/unit-3/binary-search/study-guide/YADShVFQZbqwGicqH3ub)
- [Big Idea 3: Algorithms and Programming](/ap-comp-sci-p/unit-3/review/study-guide/eOWMqAJUdtnmttaCSlis)
- [3.7 Nested Conditionals](/ap-comp-sci-p/unit-3/nested-conditionals/study-guide/iM5nw43cqaIowgYhEjyD)
- [3.17 Algorithmic Efficiency](/ap-comp-sci-p/unit-3/algorithmic-efficiency/study-guide/jGSWIqW49BtrQ8dqCWFd)
- [3.10 Lists](/ap-comp-sci-p/unit-3/lists/study-guide/mCE6meIGp5pqs1y5ym3h)
- [3.18 Undecidable Problems](/ap-comp-sci-p/unit-3/undecidable-problems/study-guide/q0SSR2ddayx397Hy6ztA)
- [3.1 Variables and Assignments](/ap-comp-sci-p/unit-3/variables-assignments/study-guide/vtJhAf5XFOkm1uHNDMvh)

## Practice Preview

### Multiple-choice practice

- **AP-style practice question**: Practice 4: Code Analysis | The variable `age` is initialized to `60`. The following code segment is executed:

`type = "Regular"`
`if (age > 18) {`
`  if (age > 65) {`
`    type = "Senior"`
`  } else {`
`    type = "Adult"`
`  }`
`}`

What is the final value of `type`?
- **AP-style practice question**: Practice 1: Computational Solution Design | A robot's navigation algorithm uses a loop to `MoveForward()` repeatedly. The current loop condition is `REPEAT UNTIL (onGoal)`, which stops the robot only when it reaches the goal. A programmer wants to modify the algorithm so the robot also stops if it hits a wall (`onWall` is true). Which loop condition achieves this?
- **AP-style practice question**: Practice 1: Computational Solution Design | A student has access to two correct algorithms: `Sum(list)`, which returns the sum of all numbers in a list, and `Count(list)`, which returns the number of elements in a list. Which approach best combines these existing algorithms to calculate the average of a non-empty list?
- **AP-style practice question**: Practice 1: Computational Solution Design | An algorithm finds the maximum value in a list of positive integers by initializing a variable `maxVal` to 0 and updating it whenever a larger number is found. A programmer wants to modify this algorithm to find the minimum value instead. Which set of changes ensures the algorithm works correctly for any list of positive integers?
- **AP-style practice question**: Practice 3: Abstraction in Program Development | A student is writing a program to process a large dataset of exam scores. Instead of writing a loop to sum the scores and divide by the count, the student uses a pre-existing library function `calculateMean(list)`. Which statement best explains how this choice manages complexity?
- **AP-style practice question**: Practice 3: Abstraction in Program Development | A programmer is creating an algorithm to calculate the range of a list of numbers by subtracting the minimum value from the maximum value. The programmer decides to use two existing, pre-tested procedures, `findMax(list)` and `findMin(list)`, rather than writing a new loop to find both values simultaneously. Which of the following best explains how this decision manages complexity?

## Key Terms

- **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.

## Common Mistakes

- **Using 0-based indexing instead of 1-based**: 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.
- **Misreading REPEAT UNTIL as REPEAT WHILE**: 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.
- **Forgetting that assignment copies the value at that moment**: 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.
- **Confusing parameters and arguments**: 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.
- **Applying binary search to unsorted data**: 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.

## Exam Connections

- **Code tracing on multiple-choice questions**: 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.
- **Explaining abstraction and complexity management**: 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.
- **Comparing algorithms and identifying limits**: 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.

## Final Review Checklist

- **Trace variable assignments**: Practice following a sequence of assignment statements line by line, applying the most-recent-assignment rule to determine what each variable holds at any point.
- **Evaluate Boolean and arithmetic expressions**: Work through expressions using MOD, relational operators, and NOT/AND/OR. Apply order of operations and check truth values step by step.
- **Trace conditionals and loops**: Given a code segment with IF/ELSE or REPEAT UNTIL, substitute specific input values and follow every branch or iteration to determine the output or side effect.
- **Apply list operations correctly**: Practice INSERT, REMOVE, APPEND, and FOR EACH traversal using 1-based indexing. Track how list length changes after each operation.
- **Explain binary search requirements and efficiency**: State that binary search requires sorted data and explain why it reaches a result faster than linear search on large sorted data sets.
- **Distinguish procedural and data abstraction**: Explain how procedures hide implementation details and how lists group related values under one name, and connect both to managing program complexity.
- **Classify algorithm efficiency and problem decidability**: Identify whether an algorithm runs in reasonable or unreasonable time, recognize when a heuristic is appropriate, and distinguish decidable from undecidable problems.

## Study Plan

- **Start with variables, expressions, and data types (3.1-3.4)**: Review the left-arrow assignment operator, trace multi-step assignment sequences, and practice evaluating arithmetic expressions with MOD. Then work through string concatenation and substring examples using the topic guides for 3.1, 3.2, 3.3, and 3.4.
- **Build fluency with Boolean logic and control structures (3.5-3.8)**: Practice writing and evaluating NOT, AND, and OR expressions. Then trace IF, IF/ELSE, nested conditionals, REPEAT n TIMES, and REPEAT UNTIL with specific input values. Use the topic guides for 3.5 through 3.8 and test yourself with available practice questions.
- **Work through algorithm design and list operations (3.9-3.11)**: Review common building-block algorithms (max, min, sum, divisibility). Practice all list operations with 1-based indexing, including INSERT and REMOVE with their shifting behavior. Then study binary search requirements and efficiency using the topic guides for 3.9, 3.10, and 3.11.
- **Review procedures, libraries, and random values (3.12-3.15)**: Trace procedure calls by mapping arguments to parameters and following flow of control through RETURN. Explain how procedural abstraction and modularity manage complexity. Review what APIs and documentation provide, and practice evaluating RANDOM(a, b) expressions for all possible results.
- **Finish with simulations, efficiency, and limits (3.16-3.18)**: Explain what a simulation abstracts and where bias can enter. Classify algorithms as reasonable or unreasonable time and identify when a heuristic is appropriate. Distinguish decidable from undecidable problems using the topic guides for 3.16, 3.17, and 3.18. Use the AP score calculator to estimate your overall score after completing practice questions.

## More Ways To Review

- [Topic study guides](/ap-comp-sci-p/unit-3#topics)
- [FRQ practice](/ap-comp-sci-p/frq-practice)
- [Cram archive videos](/cram-archives?subject=ap-computer-science-principles&unit=unit-3)
- [Cheatsheets](/ap-comp-sci-p/cheatsheets/unit-3)
- [Key terms](/ap-comp-sci-p/key-terms)

## FAQs

### What topics are covered in AP CSP Unit 3?

AP CSP Unit 3 covers 18 topics across algorithms and programming: Variables and Assignments, Data Abstraction, Mathematical Expressions, Strings, Boolean Expressions, Conditionals, Nested Conditionals, Iteration, Developing Algorithms, Lists, Binary Search, Calling and Developing Procedures, Libraries, Random Values, Simulations, Algorithmic Efficiency, and Undecidable Problems. These topics build on each other, starting with basic variables and expressions, then moving into control flow (conditionals and iteration), and finally tackling more advanced ideas like procedural abstraction and the limits of computation. See the full breakdown at [/ap-comp-sci-p/unit-3](/ap-comp-sci-p/unit-3).

### What's on the AP CSP Unit 3 progress check (MCQ and FRQ)?

The 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](/ap-comp-sci-p/unit-3) is a solid way to prepare before you take the progress check.

### How do I practice AP CSP Unit 3 FRQs?

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](/ap-comp-sci-p/unit-3).

### Where can I find AP CSP Unit 3 practice questions?

You can find AP CSP Unit 3 multiple-choice and practice test questions at [/ap-comp-sci-p/unit-3](/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.

### How should I study AP CSP Unit 3?

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](/ap-comp-sci-p/unit-3) for topic guides and practice questions to check your understanding along the way.

## Structured Data

```json
{"@context":"https://schema.org","@type":"FAQPage","inLanguage":"en","mainEntity":[{"@type":"Question","@id":"https://fiveable.me/ap-comp-sci-p/unit-3#what-topics-are-covered-in-ap-csp-unit-3","name":"What topics are covered in AP CSP Unit 3?","acceptedAnswer":{"@type":"Answer","text":"AP CSP Unit 3 covers 18 topics across algorithms and programming: Variables and Assignments, Data Abstraction, Mathematical Expressions, Strings, Boolean Expressions, Conditionals, Nested Conditionals, Iteration, Developing Algorithms, Lists, Binary Search, Calling and Developing Procedures, Libraries, Random Values, Simulations, Algorithmic Efficiency, and Undecidable Problems. These topics build on each other, starting with basic variables and expressions, then moving into control flow (conditionals and iteration), and finally tackling more advanced ideas like procedural abstraction and the limits of computation. See the full breakdown at <a href=\"/ap-comp-sci-p/unit-3\">/ap-comp-sci-p/unit-3</a>."}},{"@type":"Question","@id":"https://fiveable.me/ap-comp-sci-p/unit-3#whats-on-the-ap-csp-unit-3-progress-check-mcq-and-frq","name":"What's on the AP CSP Unit 3 progress check (MCQ and FRQ)?","acceptedAnswer":{"@type":"Answer","text":"The 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 <a href=\"/ap-comp-sci-p/unit-3\">/ap-comp-sci-p/unit-3</a> is a solid way to prepare before you take the progress check."}},{"@type":"Question","@id":"https://fiveable.me/ap-comp-sci-p/unit-3#how-do-i-practice-ap-csp-unit-3-frqs","name":"How do I practice AP CSP Unit 3 FRQs?","acceptedAnswer":{"@type":"Answer","text":"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 <a href=\"/ap-comp-sci-p/unit-3\">/ap-comp-sci-p/unit-3</a>."}},{"@type":"Question","@id":"https://fiveable.me/ap-comp-sci-p/unit-3#where-can-i-find-ap-csp-unit-3-practice-questions","name":"Where can I find AP CSP Unit 3 practice questions?","acceptedAnswer":{"@type":"Answer","text":"You can find AP CSP Unit 3 multiple-choice and practice test questions at <a href=\"/ap-comp-sci-p/unit-3\">/ap-comp-sci-p/unit-3</a>. 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."}},{"@type":"Question","@id":"https://fiveable.me/ap-comp-sci-p/unit-3#how-should-i-study-ap-csp-unit-3","name":"How should I study AP CSP Unit 3?","acceptedAnswer":{"@type":"Answer","text":"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.\n- **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.\n- **Connect simulations to randomness.** Topics 3.15 and 3.16 (Random Values and Simulations) are often tested together, so study them as a pair.\n- **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 <a href=\"/ap-comp-sci-p/unit-3\">/ap-comp-sci-p/unit-3</a> for topic guides and practice questions to check your understanding along the way."}}]}
```
