Programming and Algorithms
What the exam tests
Algorithms are finite, ordered steps that solve a problem. The exam tests algorithm properties, pseudocode and flowcharts, sequence/selection/iteration, variables, functions, testing and basic searching and sorting.
Core rules
- A valid algorithm must be unambiguous, finite, effective and have defined inputs and outputs.
- Sequence executes steps in order; selection uses IF/ELSE; iteration uses loops such as WHILE or FOR.
- Dry running means tracing variable values line by line. Desk checking finds logic errors, not just syntax errors.
- Linear search checks items in order; binary search requires sorted data and halves the search space. Bubble sort repeatedly swaps adjacent out-of-order items.
Worked example
Pseudocode: SET total = 0 FOR i = 1 TO 5 SET total = total + i ENDFOR OUTPUT total The trace is: i=1 total=1; i=2 total=3; i=3 total=6; i=4 total=10; i=5 total=15. Output is 15. Reasoning: the loop runs five times, and total accumulates the running sum. If the loop began at 0, the output would still be 15 because adding 0 changes nothing; if it ended at 4, the output would be 10.
Traps that cost marks
Do not confuse assignment (=) with comparison (= or == in pseudocode conventions). Watch off-by-one loop bounds. Integer division discards the remainder; use MOD for remainder. In flowcharts, a diamond is a decision, not a process. Do not claim binary search works on unsorted data.
Exam focus
Expect pseudocode tracing, flowchart symbol matching and comparison of search algorithms.