What is an algorithm, and how are sequencing, selection and iteration combined to solve problems?
Topic 3.9 Developing Algorithms: an algorithm is a finite set of instructions that accomplishes a task, built by combining sequencing, selection and iteration, and different algorithms can solve the same problem.
A focused answer to AP CSP Topic 3.9, covering what an algorithm is, the three building blocks (sequencing, selection, iteration), expressing algorithms in pseudocode and language, that different algorithms can solve the same problem, and standard list algorithms.
Reviewed by: AI editorial process; not yet individually human-reviewed
Have a quick question? Jump to the Q&A page
Jump to a section
What this topic is asking
The College Board (Topic 3.9) wants you to develop algorithms: design and express the step-by-step logic that solves a problem. Every algorithm is built from three building blocks: sequencing (steps in order), selection (conditionals) and iteration (loops). You must combine these to solve problems, express algorithms in pseudocode, and understand that different algorithms can solve the same problem (and may differ in clarity or efficiency).
What an algorithm is
The three building blocks
For example, "count the even numbers in a list" uses sequencing (set up a counter, then loop, then display), iteration (loop over the list) and selection (test each value).
Different algorithms, same problem
A single problem usually has many correct algorithms. To find the largest value in a list you could scan once tracking the maximum, or sort the list and take the last element. Both work; they differ in how much work they do. The CED wants you to recognize that algorithms can be compared for correctness, clarity and efficiency (see algorithmic efficiency).
Standard list algorithms
Several patterns recur and are worth knowing cold:
- Sum / count: traverse, accumulate a running total or counter.
- Maximum / minimum: traverse, keep the best value seen so far (initialised to the first element).
- Search: traverse, check each element against a target, report found or not found.
Try this
Q1. Name the three building blocks of algorithms. [3 points]
- Cue. Sequencing (steps in order), selection (conditionals), and iteration (loops).
Q2. Explain what it means that different algorithms can solve the same problem. [2 points]
- Cue. A problem can have several correct step-by-step solutions; they may differ in clarity or efficiency but all produce the right result, for example finding a maximum by scanning versus by sorting.
Exam-style practice questions
Practice questions written in the style of College Board exam questions on this dot point, with worked answer explainers. The year tag is the paper they imitate, not the source.
AP 2022 (style)1 marksMultiple choice. Which of the following best describes an algorithm?
(A) A single instruction that runs once.
(B) A finite set of instructions that accomplishes a specific task.
(C) A list of data values with no instructions.
(D) A programming language.
Show worked answer β
The answer is (B).
An algorithm is a finite sequence of instructions that, when followed, accomplishes a specific task or solves a problem. (A) is too narrow; algorithms usually combine many steps. (C) describes data, not a procedure. (D) a language is the medium you express an algorithm in, not the algorithm itself.
Markers reward the definition: a finite set of clear instructions that accomplishes a task.
AP 2021 (style)3 marksFree response (code writing). Write AP CSP pseudocode that counts how many even numbers are in a list `nums` and displays the count.
Show worked answer β
A 3-point question combining iteration, selection and the MOD operator.
evens β 0
FOR EACH n IN nums
{
IF (n MOD 2 = 0)
{
evens β evens + 1
}
}
DISPLAY(evens)
Point 1: initialise the counter evens to 0. Point 2: traverse the list (iteration) and test each value with n MOD 2 = 0 (selection plus MOD) to detect even numbers. Point 3: increment the counter and display it after the loop. This algorithm combines sequencing, selection and iteration, the three building blocks. A common error is using n / 2 = 0 instead of n MOD 2 = 0.
Related dot points
- Topic 3.8 Iteration: iteration (REPEAT n TIMES and REPEAT UNTIL) repeats a block of code, with the number of repetitions controlled by a count or a condition.
A focused answer to AP CSP Topic 3.8, covering REPEAT n TIMES and REPEAT UNTIL loops in AP CSP pseudocode, counting iterations, accumulating values, infinite loops and off-by-one errors, and tracing loop execution.
- Topic 3.6/3.7 Conditionals and Nested Conditionals: conditional (IF/ELSE) statements select which code runs based on a Boolean condition, and nested conditionals handle multiple decision paths.
A focused answer to AP CSP Topics 3.6 and 3.7, covering IF and IF/ELSE selection, the role of the Boolean condition, nested conditionals for multiple paths, tracing which branch runs, and writing decision logic in AP CSP pseudocode.
- Topic 3.10 Lists: a list is an ordered collection of elements accessed by index; AP CSP lists are 1-indexed and support traversal and modification with APPEND, INSERT and REMOVE.
A focused answer to AP CSP Topic 3.10, covering lists as ordered collections, 1-based indexing in AP CSP pseudocode, accessing elements, traversing with FOR EACH and REPEAT, list operations (APPEND, INSERT, REMOVE, LENGTH), and why lists scale data processing.
- Topic 3.3/3.5 Mathematical and Boolean Expressions: programs evaluate arithmetic (including MOD) and Boolean expressions using relational and logical operators (AND, OR, NOT) that produce true or false.
A focused answer to AP CSP Topics 3.3 and 3.5, covering arithmetic operators and the MOD operator, relational operators, the Boolean operators AND, OR and NOT with truth tables, evaluating compound conditions, and the common uses of MOD such as testing even or odd.
- Topic 3.11/3.17/3.18 Binary Search and Efficiency: binary search finds a value in a sorted list far faster than linear search, and algorithms are compared by efficiency, with some problems being unsolvable or only approximable.
A focused answer to AP CSP Topics 3.11, 3.17 and 3.18, covering linear versus binary search, why binary search needs a sorted list, reasonable versus unreasonable running time, polynomial versus exponential growth, heuristics, and undecidable problems.
Sources & how we know this
- AP Computer Science Principles Course and Exam Description β College Board (2025)