Define the start and finish
An algorithm is a clearly specified set of rules or steps that produces a result. Before writing the steps, identify the input—the information the process receives—and the output—the result it must produce.
The steps should be ordered, have a clear stopping point, and be precise enough that someone can follow the same input without guessing what the writer meant. Pseudocode lets you write that logic in plain, structured language before choosing a programming language.
Trace before you trust
Tracing means following an algorithm one step at a time with a specific input and recording what changes. A normal example can show that the basic path works, but it may not expose every problem.
An edge case is an unusual input at or near a limit of what the algorithm accepts. Examples include an empty list, equal values, zero, a negative number, or the smallest allowed input. If a step becomes unclear or the process cannot finish, revise the algorithm and trace it again.
Remember these ideas
Key ideas
- An algorithm connects defined inputs to an intended output through ordered steps.
- Precise instructions avoid hidden choices and ambiguous words.
- Tracing makes the current state visible after each step.
- Edge cases reveal gaps that an ordinary example may miss.
Make the reasoning visible
Write an average-score algorithm
- 1
Input: a list containing at least one quiz score. Output: the arithmetic mean, or average, of those scores.
- 2
Set total to 0, then add each score in the list to total.
- 3
Count how many scores are in the list and divide total by that count.
- 4
Test [80, 90, 100]: total is 270, count is 3, and the output is 90. Because the list must contain at least one score, specify that the algorithm rejects an empty list before trying to divide.
Try the next step
Rewrite and trace an ambiguous step
For a nonempty list of scores, an instruction says, “Look through the scores and choose the best one.” Rewrite it so the output is the highest numerical score, including what to do when scores tie. Then trace your steps for [6, 9, 9, 2] and state the output.
Which words in everyday instructions tend to hide a decision that an algorithm must make explicit?