Introduction
This question tested the following topics/items:
- Problem-solving methods: stepwise refinement and bottom-up design
- Control constructs in structured programming
- Determining the output of an algorithm with nested selection
- Completing a trace table for a while loop
Part a) i)
Stepwise refinement is a method where the problem is first written as a few major steps, and each step is then broken down (refined) repeatedly into smaller, more detailed sub-steps until each step is simple enough to be converted directly into program code.
See this note: Introduction to Top-Down Stepwise Refinement
Part a) ii)
In the bottom-up method, the smallest, most detailed sub-problems (modules) are solved, coded and tested first. These modules are then combined to form larger modules, and so on, until the complete solution to the overall problem is built.
Part b)
- Sequence
- Selection (e.g. IF-THEN-ELSE)
- Iteration/Repetition (looping, e.g. FOR, WHILE)
See this note: Constructs used in structured programming
Part c) i)
GREEN
Part c) ii)
BLUE GREEN
Part c) iii)
RED GREEN
Explanation
When num = 1, the condition num > 1 is false, so the whole inner IF is skipped and only GREEN is printed. When num = 2, num > 1 is true but num == 3 is false, so the ELSE prints BLUE, then GREEN is printed. When num = 3, both conditions are true, so RED is printed, then GREEN. GREEN is always printed because it is outside both IF statements.
See this note: The Selection Construct
Part d)
Initially x = 9, y = 2
| Iteration | x | y | |
|---|---|---|---|
| 1 | 8 | 3 | 8, 3 |
| 2 | 7 | 4 | 7, 4 |
| 3 | 6 | 5 | 6, 5 |
| 4 | 5 | 6 | 5, 6 |
| 5 |
Further explanation
Each time through the loop, y is increased by 1 and x is decreased by 1, then x and y are printed. After the 4th iteration, x = 5 and y = 6, so the condition x > y (5 > 6) is false and the loop ends. There is no 5th iteration, so that row stays empty.
See this note: SBA-How to Approach a Dry run using test data and trace tables to uncover errors in your algorithm, Repetition (Iteration) Constructs
Links to Notes
© 2026 Vedesh Kungebeharry. All rights reserved.