AP® Computer Science Principles · Big Idea 3 · Topic 3.3
Algorithms and Sequencing
An algorithm is a precise, ordered sequence of steps that solves a problem, built from three building blocks: sequencing, selection, and iteration. Change the order and you often change or break the result.
Sequencing just means doing steps in a specific order, one after another. It sounds obvious, but order is the whole game: the same steps run in a different order can produce a different answer or stop working altogether. That is because most steps depend on the state left behind by the steps before them. A step that halves total only makes sense once total already holds a meaningful number. Swap it earlier and the rest of the algorithm is now working with the wrong value.
Every algorithm, no matter how complex, is built from three ingredients: sequencing (steps in order), selection (branching with if/else based on a condition), and iteration (repeating steps with a loop). Combine them and you can express any process a computer can carry out. The same algorithm can be written three ways without changing its meaning: as natural language ('set total to 0, add the first number, add the second number, divide by 2'), as a flowchart (boxes and arrows showing the order and any branches or loops), or as pseudocode (structured, code-like lines that are not tied to any real programming language). All three describe the identical sequence of steps.
This matters because an algorithm is the idea, not the implementation. A program is one specific expression of an algorithm, written in a real language like Python or Java, that a computer can actually run. The same algorithm can become many different programs, and a badly sequenced algorithm will produce a buggy program no matter how carefully it is coded, which is why the next step in the course is learning to trace and test these sequences carefully.
Key terms
- Algorithm
- A precise, ordered sequence of steps that solves a problem or completes a task.
- Sequencing
- Carrying out steps one after another in a specific, meaningful order.
- Selection
- Branching behavior where a condition decides which of two or more paths an algorithm takes.
- Iteration
- Repeating one or more steps, usually until a condition is met.
- Pseudocode
- Structured, code-like writing that expresses an algorithm's steps without following a specific programming language's syntax.
Watch it explained
- How it worksHow do sequencing, selection, and iteration combine to build any algorithm at all?
- How it worksWalk me through one algorithm expressed as natural language, as a flowchart, and as pseudocode.
- Worked exampleTrace the sequence that sets total to 0, adds 8, adds 12, and then halves total.
- Common mistakeWhy isn't an algorithm the same thing as a program?
Check yourself
End of topic.