Algorithms and programming
Trace AP algorithms and lists
Read AP assignment, selection, repetition, and one-based list notation.
Algorithm examples use AP reference notation, including one-based list indices.
Read assignment in order
An assignment evaluates the right-hand expression before replacing the value on the left. Equality compares values; it does not update them. Track each variable after every statement, especially when one variable depends on another.
AP reference lists start at index 1. In this example, the list stores three marks and FOR EACH visits each mark once. Selection decides whether a mark increases the count. The final displayed count is 2.
marks ← [42, 65, 80]
passes ← 0
FOR EACH mark IN marks
{
IF (mark ≥ 50)
{
passes ← passes + 1
}
}
DISPLAY(passes)Choose the right algorithm
A linear search checks elements one at a time and works on an unsorted list. Binary search discards half the remaining search range at each step, but requires a sorted list. An algorithm can be correct and still take too long for a very large input.
To evaluate a loop, test an empty list, a list of one item, and a list with repeated items. Decide whether the question asks for the first match, every match, a count, or a Boolean result before writing the algorithm.
Check yourself
What is the index of 65 in the AP list [42, 65, 80]?Show answer
2. AP reference notation uses one-based list indexing.
References used to build these lessons
We used these official documents as references when building this course's lessons. They are the sources for the syllabus structure and course requirements.
College Board · Effective fall 2023