The notes are student-facing. Each lesson includes definitions in context, a worked example, a common error, and questions with solutions hidden until students choose to see them.
Lesson 1.1 · Workbook pages 8-10Learning goal: Write, trace, and revise a precise finite sequence of instructions.
CodeHS 2025 Python: 1.1.1 Welcome to AP CSP; 1.2.1 Introduction to Programming With Karel; 1.2.4 Your First Karel Program; 1.3.4 Make a Tower
AP Classroom topics: 1.2 / 1.3; preview 3.9 — open assigned videos in
AP Classroom.
Learn & recordVisualize & planApply & reflect
Open the public CodeHS course outline for verified activity numbering; teacher assigns the selections in class.
Lesson 1.1 · Blocks 1–2
Algorithms and precise instructions
Core idea: An algorithm is a finite sequence of precise steps that performs a task. The computer does exactly what the instructions tell it to do—not what the author intended. A useful algorithm specifies its starting conditions, allowable operations, and the result it should produce.
What makes an algorithm reliable?
- Precision: each command has one clear meaning.
- Sequence: steps run in a defined order unless control structures change that order.
- Preconditions: assumptions about the starting state are stated.
- Termination: the process eventually finishes for the intended inputs.
- Correctness: it produces the required result for its specified inputs.
Worked example: Follow the robot, not your intuition.Robot begins at (1,1), facing east. Commands are MOVE, LEFT, MOVE, RIGHT, MOVE. Each MOVE advances exactly one grid cell; LEFT and RIGHT rotate 90° without moving.
- MOVE → (2,1), east
- LEFT → (2,1), north
- MOVE → (2,2), north
- RIGHT → (2,2), east
- MOVE → (3,2), east
Final position: (3,2), facing east. Coordinates in this example use positive y upward; the robot simulator below uses screen-grid coordinates with y increasing downward.
Common mistake: Treating turns as movement, or assuming that a robot knows how far to travel when told to “move toward the wall.” State the number of cells or an explicit stopping condition.
Check your understanding
1. A robot starts facing north. It executes RIGHT, MOVE, MOVE, LEFT, MOVE. What direction does it face at the end?
Show solution
North. RIGHT makes it face east; the two moves do not change direction; LEFT returns it to north; the final move also preserves direction.
2. Why is “move a little farther” not a suitable robot command?
Show solution
“A little” has no precise distance or testable condition. Replace it with something like “MOVE twice” or “REPEAT UNTIL the next cell is a wall.”
3. Challenge. An algorithm reaches the goal when the robot faces east but fails from the same cell when it faces south. Is the algorithm necessarily incorrect?
Show solution
Not necessarily. If facing east is an explicit precondition, success from the specified state can be sufficient. If it claims to work from any starting orientation, the south-facing case is a counterexample.
Lesson 1.2 · Workbook pages 11-13Learning goal: Explain a program’s purpose, behavior, inputs, outputs, and iterative improvement.
CodeHS 2025 Python: 1.1.2 Why AP CSP?; 3.1.1 What is Code? (preview); 3.2.1 Uses of Programs (preview)
AP Classroom topics: 1.1 / 1.2 / 1.3 — open assigned videos in
AP Classroom.
Learn & recordVisualize & planApply & reflect
Open the public CodeHS course outline for verified activity numbering; teacher assigns the selections in class.
Lesson 1.2 · Blocks 3–4
Program purpose, function and iterative design
Core idea: A program's purpose is why it was made. Its function is what it does; its behavior is what happens when it runs. Distinguishing these concepts helps us explain a program without simply listing its instructions.
InputData provided to a program, such as a temperature reading or a button press.
OutputInformation or an action produced by a program, such as a message or a motor command.
Plan → create → test → revise
Programs are commonly developed iteratively. A first version may satisfy some needs while exposing weaknesses. User feedback, test evidence, and changing requirements inform subsequent revisions.
Worked example: School arrival alertA program accepts a bus's estimated arrival time and notifies riders when the bus is at most five minutes away.
- Purpose: help riders avoid missing the bus.
- Input: estimated minutes until arrival.
- Processing: compare that value to 5.
- Output: an alert or a “not yet” message.
- Behavior: given input 4, it displays “Bus arriving soon.”
A tester reports alerts at negative arrival times. One revision is to check that the data is valid before displaying the warning.
Common mistake: “It displays a red warning” describes a behavior. “It helps riders prepare for an approaching bus” describes its purpose.
Check your understanding
1. A fitness app counts daily steps and displays a chart. Give one input and one output.
Show solution
Input: step-count data from a sensor or stored records. Output: a chart of daily steps. Other accurate examples may be acceptable.
2. A developer changes a program after classmates report that the directions are confusing. What development process does this demonstrate?
Show solution
Iterative development: feedback informs a revision, which can then be tested again.
3. Challenge. Explain why a program could behave as designed but still fail at its purpose.
Show solution
All programmed steps may run correctly while the design solves the wrong problem. For example, a bus alert may correctly display at five minutes but be too late for riders who need ten minutes to reach the stop.
Lesson 1.3 · Workbook pages 14-16Learning goal: Break a complex problem into testable, meaningful subtasks.
CodeHS 2025 Python: 1.5.1 Functions in Karel; 1.6.1 Top Down Design and Decomposition; 1.6.4 The Two Towers; 1.7.1 Commenting Your Code
AP Classroom topics: 1.3; preview 3.12 — open assigned videos in
AP Classroom.
Learn & recordVisualize & planApply & reflect
Open the public CodeHS course outline for verified activity numbering; teacher assigns the selections in class.
Lesson 1.3 · Block 5
Decomposition and top-down design
Core idea: Decomposition separates a large problem into smaller problems that can be designed, tested, and discussed more easily. In top-down design, start with the overall goal, then define the subtasks required to achieve it.
Worked example: Design a delivery robotOverall task: deliver a package from the entry area to a classroom.
DELIVER_PACKAGE()
NAVIGATE_TO_CLASSROOM()
VERIFY_DESTINATION()
DROP_OFF_PACKAGE()
CONFIRM_DELIVERY()Now refine NAVIGATE_TO_CLASSROOM() into smaller tasks, such as EXIT_ENTRY_AREA(), FOLLOW_HALLWAY(), and TURN_AT_INTERSECTION(). Each subtask should have a clear responsibility and expected outcome.
Common mistake: Decomposition does not automatically make code shorter or faster. Its key benefit is making a complex system easier to reason about, divide into tasks, and test.
Check your understanding
1. Break “prepare a school newsletter” into at least three meaningful subtasks.
Show sample answer
Collect announcements, edit and organize stories, format the newsletter, and distribute the final version. Other sensible decompositions are valid.
2. Why should each subtask have a clearly defined input and outcome?
Show solution
It lets other parts of the system use the subtask predictably and makes each part easier to test independently.
3. Challenge. Two teams both divide a navigation program into functions. One team creates one function for every single move. Which design is more useful, and why?
Show sample answer
Functions that represent meaningful subtasks (such as navigating a hallway) usually manage complexity more effectively than one function per trivial command, although the best boundaries depend on the problem.
Lesson 1.4 · Workbook pages 17-19Learning goal: Use a meaningful procedure name to hide details without changing expected behavior.
CodeHS 2025 Python: 1.8.1 Abstraction; 1.8.3 Abstracting Away build_tower; 1.8.4 Abstracting Your Day; 1.7.4 The Two Towers + Comments
AP Classroom topics: 1.3; preview 3.12 / 3.13 — open assigned videos in
AP Classroom.
Learn & recordVisualize & planApply & reflect
Open the public CodeHS course outline for verified activity numbering; teacher assigns the selections in class.
Lesson 1.4 · Block 6
Abstraction: hide details without hiding meaning
Core idea: An abstraction keeps the important features of something visible while hiding implementation details that are unnecessary for the current task. A named procedure can let someone reason about what an operation accomplishes before investigating how it is implemented.
Worked example: Two levels of the same algorithmDetailed version:
MOVE
MOVE
LEFT
MOVE
RIGHT
Higher-level version:
NAVIGATE_AROUND_CORNER()
If NAVIGATE_AROUND_CORNER() faithfully performs the original sequence, a caller can use the meaningful name without reading every lower-level instruction. This example uses a descriptive procedure name, not a predefined AP exam robot operation.
Decomposition versus abstraction
Decomposition asks, “What smaller tasks make up the big problem?” Abstraction asks, “Which details can we hide so the task is easier to use and understand?” They are related, but not identical.
Common mistake: Hiding a faulty implementation does not fix it. An abstraction must still provide the behavior its name or contract promises.
Check your understanding
1. Which details are hidden when a program calls
DRAW_SQUARE()?
Show solution
The individual movement and turning commands, or other lower-level drawing operations, can be hidden behind the procedure call.
2. A team replaces four repeated commands with a named procedure but changes the ending position. Has it preserved the intended behavior?
Show solution
No, not if the original ending position was required. A useful abstraction must preserve its specified behavior.
3. Challenge. Give an example where showing too many implementation details makes a program harder to understand.
Show sample answer
A main program that repeats dozens of low-level motion commands may obscure its overall goal. A few named procedures can expose the sequence of major tasks while keeping detailed instructions separate.
Lesson 1.5 · Workbook pages 20-22Learning goal: Use evidence to identify syntax, runtime, and logic errors and justify fixes.
CodeHS 2025 Python: 1.2.6 Dancing Karel; 1.15.1 Debugging Basics; 1.15.3 Debug: The Two Towers; 1.15.5 Debugging From Error Messages
AP Classroom topics: 1.4 — open assigned videos in
AP Classroom.
Learn & recordVisualize & planApply & reflect
Open the public CodeHS course outline for verified activity numbering; teacher assigns the selections in class.
Lesson 1.5 · Block 7
Identifying and correcting errors
Core idea: Testing compares expected results with actual results. Debugging investigates the cause of a mismatch and changes the program in a way supported by evidence.
Syntax errorCode violates the rules of its language and generally cannot be interpreted or compiled successfully.
Runtime errorA problem occurs during execution; the program may stop unexpectedly or fail to complete an operation.
Logic errorThe program runs but gives behavior inconsistent with its requirements.
Boundary caseAn input at or near the edge of an allowed range, where faulty conditions often appear.
Worked example: Off-by-one alertRule: A student receives a certificate with a score of 80 or higher. Program condition:
IF (score > 80)
{
DISPLAY("Certificate earned")
}- Test score 81 → expected yes, actual yes.
- Test score 79 → expected no, actual no.
- Test score 80 → expected yes, actual no.
Diagnosis: a logic error at the boundary. Correction: change score > 80 to score ≥ 80.
Common mistake: A program can run without crashing and still be wrong. Successful execution does not prove correct output.
Check your understanding
1. A program divides by a user-supplied value and crashes when the value is zero. What general category of error does this illustrate?
Show solution
A runtime error caused by an invalid operation during execution. The input zero is an important test case.
2. A program uses
age < 18 to represent “age 18 and younger.” What is wrong?
Show solution
It excludes age 18. Use age ≤ 18 to include the boundary.
3. Challenge. Why should a bug report record both expected and observed behavior?
Show solution
The comparison provides reproducible evidence of the failure and helps locate the statement responsible rather than relying on vague reports like “it doesn't work.”
Lesson 1.6 · Workbook pages 23-25Learning goal: Trace changing state and design normal, boundary, and unusual test cases.
CodeHS 2025 Python: 1.15.2 Debugging Basics; 1.16.1 Karel Algorithms; 1.16.2 Quiz: Which Control Structure?; 1.19.1 Introduction to Programming Quiz (when ready)
AP Classroom topics: 1.4; preview 3.5 / 3.9 — open assigned videos in
AP Classroom.
Learn & recordVisualize & planApply & reflect
Open the public CodeHS course outline for verified activity numbering; teacher assigns the selections in class.
Lesson 1.6 · Blocks 8–10
Testing strategies and trace tables
Core idea: A trace table records how variable values change during execution. A test suite selects inputs deliberately, including typical inputs, boundary values, and invalid inputs if those must be handled. One successful test does not prove correctness for every possible input.
Worked example: Trace a variable carefullyvalue ← 2
value ← value + 5
value ← value * 3
DISPLAY(value)
| Executed step | value after step |
|---|
| value ← 2 | 2 |
| value ← value + 5 | 7 |
| value ← value * 3 | 21 |
| DISPLAY(value) | 21 |
Final output: 21. Assignment changes the stored value; it is not a mathematical equation that remains true forever.
Design tests around requirements
If a website accepts ages from 13 through 18 inclusive, useful tests include 12, 13, 15, 18, and 19. This suite checks values just below, at, inside, at, and just above the permitted interval.
Common mistake: Testing five random middle values may miss the exact boundary that contains the bug. Choose test cases based on the required behavior.
Check your understanding
1. Trace
x ← 3; x ← 2 * x; x ← x - 4. What is the final value?
Show solution
3 → 6 → 2, so the final value is 2.
2. A program accepts temperatures from 0 through 100 inclusive. Which inputs would you choose to test the two boundaries?
Show solution
At minimum, test 0 and 100. Include -1 and 101 to verify that just-outside values are rejected.
3. Challenge. A student claims an algorithm works for every nonnegative integer. You find one nonnegative input that produces an incorrect result. What can you conclude?
Show solution
The universal claim is false. A single valid counterexample is enough to disprove “works for every nonnegative integer.”
Lesson 1.7 · Workbook pages 26-28Learning goal: Compare growth of work and explain heuristic vs optimal solutions.
CodeHS 2025 Python: 1.16.1 Karel Algorithms (support only); use site Efficiency Lab D for this topic
AP Classroom topics: 3.17 / 3.18 preview; revisit Unit 5 — open assigned videos in
AP Classroom.
Learn & recordVisualize & planApply & reflect
Open the public CodeHS course outline for verified activity numbering; teacher assigns the selections in class.
Lesson 1.7 · Block 10 or extension block · AP 3.17–3.18 preview
Algorithm efficiency, heuristics & computational limits
Core idea: Two algorithms can produce the same correct answer but require very different amounts of work. We often approximate efficiency by counting operations as input size n grows instead of measuring seconds on a particular computer. Sometimes an exact best answer is expensive to find; a heuristic seeks a useful answer efficiently without guaranteeing it is best.
How does the work grow?
For an illustrative algorithm that performs n operations, doubling the input doubles the work. For one requiring n × n operations, doubling the input quadruples the work. For one requiring 2^n operations, each increase of one input element doubles the work. The AP framework classifies polynomial or slower growth as reasonable time and exponential or factorial growth as unreasonable time; this is about how work scales, not a guarantee of fast performance for every small input.
Worked example: Comparing operation countsOne algorithm examines every item exactly once; a second compares every item with every other item. For a list of 10 items, they perform approximately 10 vs. 100 basic steps. For 20 items, the counts become 20 vs. 400. Both are reasonable-time growth, but the first scales more favorably.
Exact solutions, heuristics and undecidability
An exact algorithm for a shortest route seeks a provably shortest valid route. A heuristic such as “go to the nearest unvisited stop next” can quickly produce a useful route, but may miss a shorter one. A problem that takes an impractically long time is not the same as an undecidable problem, for which no algorithm can correctly decide every possible instance.
Important distinction: Time complexity, optimality and decidability are three different questions. Formal Big-O calculations are enrichment, not a required AP CSP skill.
Check your understanding
1. An algorithm needs 8 operations for 8 inputs and 16 for 16 inputs. Which growth model best matches these observations?
Show solution
Linear. Doubling input doubles work. Two observations suggest linear growth but do not prove the behavior for all inputs.
2. A second algorithm takes roughly
n² operations. What happens when the input size triples?
Show solution
The work becomes approximately nine times as large because (3n)² = 9n².
3. A nearest-neighbor route is 19 distance units; another route is 16. What can you conclude?
Show solution
The 19-unit heuristic route is not optimal, since a shorter valid route exists. The 16-unit route is not necessarily globally optimal unless you show no shorter route exists.
4. Challenge. How does an algorithm that requires billions of steps differ from an undecidable problem?
Show solution
For the first problem, a correct algorithm exists but may be impractical. For an undecidable decision problem, no algorithm can correctly answer every possible instance.