An algorithm is a finite, unambiguous sequence of instructions that solves a well-defined problem. Every algorithm must:
1. Terminate in a finite number of steps
2. Be unambiguous — each step has exactly one interpretation
3. Have a well-defined input and output
4. Be correct — produce the right output for every valid input
KEY TAKEAWAY: Algorithms are the computational heart of problem-solving. Every algorithm has structure: it begins, processes inputs through defined steps, and terminates with an output.
An algorithm begins with its name and the list of inputs (parameters).
ALGORITHM BinarySearch(A, target)
Input: Sorted array A, value target
Output: Index of target in A, or -1 if not found
Instructions are executed in order, one after another. This is the most fundamental control structure.
Variables store and update data throughout the algorithm.
max ← A[0]
count ← 0
Branch the algorithm’s path based on a condition.
if x > max then
max ← x
end if
Repeat a block of instructions multiple times.
for i ← 0 to n-1 do
...
end for
while condition do
...
end while
Encapsulate reusable logic. Support modular design.
FUNCTION max(a, b)
if a > b then return a
else return b
Output the result and terminate.
return result
ALGORITHM Name(parameter1, parameter2, ...)
// Pre-condition: what is true about inputs
// Post-condition: what is true about the output
Step 1: ...
Step 2: ...
...
return result
An algorithm is correct if, for every valid input, it produces the correct output and terminates.
Proving termination: Show that each iteration makes measurable progress towards the termination condition (e.g., the search space shrinks, a counter decrements).
Proving correctness: Use loop invariants (for iterative algorithms) or induction (for recursive algorithms).
EXAM TIP: VCAA exams may ask you to trace through an algorithm manually with given input. Lay out variable values step by step — do not skip steps.
ALGORITHM FindMax(A)
max ← A[0]
for i ← 1 to length(A) - 1 do
if A[i] > max then
max ← A[i]
end if
end for
return max
Manual trace on A = [3, 7, 2, 9, 4]:
| i | A[i] | max |
|—|------|-----|
| — | — | 3 |
| 1 | 7 | 7 |
| 2 | 2 | 7 |
| 3 | 9 | 9 |
| 4 | 4 | 9 |
Result: 9 ✓