AP CSP Unit 3: Algorithms & Programming – Complete 2025 Study Guide
AP CSP Unit 3: Algorithms & Programming — Complete 2025 Study Guide
Unit 3 is the largest and most important part of the AP Computer Science Principles curriculum. It covers algorithms, variables, loops, conditionals, lists, functions, and general problem-solving — the foundation of programming.
- Variables, expressions, and assignment
- Conditionals (IF, ELSE IF, ELSE)
- Loops (REPEAT, WHILE, FOR EACH)
- Lists and data structures
- Functions, parameters, and return values
- Algorithmic patterns (traversal, accumulation, filtering)
- Efficiency & problem-solving strategies
- AP-style questions with explanations
🧮 Variables & Assignment
Variables store information that can change during a program. They allow algorithms to track state, update values, and compute results.
Key ideas:
- Assignment uses ←, not equals
- Variables update based on the sequence of instructions
- The exam often tests variable tracing
score ← 0 score ← score + 5
The new value replaces the old value — variables do not “remember” past values.
🔁 Conditionals (IF Statements)
Conditionals let algorithms make decisions by evaluating Boolean expressions (true/false).
Boolean operators:
- AND — both must be true
- OR — at least one must be true
- NOT — reverses true/false
IF (age ≥ 18)
{
DISPLAY("Adult")
}
ELSE
{
DISPLAY("Minor")
}
Only the first true condition runs — later branches are ignored.
age = 17 → “Minor”
🔄 Loops: REPEAT, WHILE, FOR EACH
Loops repeat instructions multiple times. Understanding loop flow is crucial for the AP CSP exam.
Loop types:
- REPEAT n TIMES — fixed number of iterations
- WHILE (condition) — repeats until condition becomes false
- FOR EACH — iterates through all items in a list
Example:
counter ← 0
REPEAT 5 TIMES
{
counter ← counter + 2
}
counter ends at 10.
📜 Lists: Storing Multiple Values
Lists are one of the most important data abstractions in AP CSP.
Common list operations:
- APPEND(list, value)
- INSERT(list, index, value)
- REMOVE(list, index)
- LENGTH(list)
- list[i] — accessing an element
Traversal example:
sum ← 0
FOR EACH num IN numbers
{
sum ← sum + num
}
Filtering example:
evens ← []
FOR EACH n IN nums
{
IF (n MOD 2 = 0)
{
APPEND(evens, n)
}
}
📦 Functions, Parameters, & Return Values
Functions allow code reuse and abstraction — hiding details so the user only focuses on what the function does.
Two kinds of functions:
- Procedures — perform actions
- Functions — return values
PROCEDURE Square(x)
{
RETURN (x * x)
}
Many exam questions ask: “What value is returned?” — not displayed.
🧠 Algorithm Patterns
Many AP CSP questions use the same algorithmic building blocks.
Key patterns:
- Traversal — visit each element
- Accumulation — track a running total
- Filtering — build a new list based on a condition
- Searching — look for a specific value
- Mapping — transform each element
⏱ Algorithm Efficiency
AP CSP does not require Big-O notation, but efficiency concepts still appear.
- Fewer operations → more efficient
- Loops inside loops (nested loops) are less efficient
- Binary search is more efficient than linear search
- Removing list items repeatedly can reduce efficiency
📝 AP Exam-Style Practice Questions
Question 1
What value is displayed by the following code?
x ← 2
y ← 1
REPEAT UNTIL (x > 10)
{
x ← x * 2
y ← y + 1
}
DISPLAY(y)
Answer: 4
Question 2
What does this procedure return?
PROCEDURE Mystery(list)
{
sum ← 0
FOR EACH n IN list
{
IF (n > 5)
{
sum ← sum + n
}
}
RETURN(sum)
}
Answer: The sum of all values in the list that are greater than 5.
Question 3
What is printed by this code?
count ← 0
nums ← [3, 6, 1, 8, 2]
FOR EACH n IN nums
{
IF (n MOD 2 = 0)
{
count ← count + 1
}
}
DISPLAY(count)
Answer: 3 (Even values are 6, 8, and 2)
Question 4
What does this procedure return?
PROCEDURE DoubleEvens(list)
{
result ← []
FOR EACH x IN list
{
IF (x MOD 2 = 0)
{
APPEND(result, x * 2)
}
}
RETURN(result)
}
Answer: A list containing all even numbers from the input list, each doubled. Example: [2, 3, 8] → [4, 16]
Question 5
What value is returned?
PROCEDURE Mystery(x)
{
IF (x < 10)
{
RETURN(x * 3)
}
RETURN(x - 4)
}
Answer: If x < 10 → returns x * 3 Otherwise → returns x − 4 (This tests conditional branching.)
Need Help? Get AP CSP Tutoring
Learn About Tutoring
Get in Touch
Whether you're a student, parent, or teacher — I'd love to hear from you.
Just want free AP CS resources?
Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.
Message Sent!
Thanks for reaching out. I'll get back to you within 24 hours.
tanner@apcsexamprep.com
Courses
AP CSA, CSP, & Cybersecurity
Response Time
Within 24 hours
Prefer email? Reach me directly at tanner@apcsexamprep.com