Describe and use the process of stepwise refinement (top‑down design) to express an algorithm to a level of detail from which the task may be programmed.
| Level | Focus | Typical Output |
|---|---|---|
| 1 | Problem statement | Natural‑language description of the overall task. |
| 2 | Major sub‑tasks | Bulleted list of high‑level functions or modules. |
| 3 | Detailed steps | Pseudocode, structured English, or flow‑chart fragments. |
| 4 | Implementation ready | Executable code fragments (Python, Java, etc.). |
IF … THEN … END IF).# (or //) and explain “why”, not “what”.FOR i ← start TO end DO
…
END FOR
WHILE condition DO
…
END WHILE
IF condition THEN
…
ELSE
…
END IF
At the final refinement stage you should be able to give a simple analysis of the algorithm’s efficiency.
Given a list of numbers, determine the largest number.
INPUT L # list of numbers
max ← L[0] # initialise with first element
FOR i ← 1 TO |L| - 1 DO
IF L[i] > max THEN
max ← L[i]
END IF
END FOR
OUTPUT max
def find_max(L):
max_val = L[0]
for i in range(1, len(L)):
if L[i] > max_val:
max_val = L[i]
return max_val
Sort a list of numbers into non‑decreasing order using the insertion‑sort method.
FOR j ← 2 TO n DO
key ← A[j]
i ← j - 1
WHILE i > 0 AND A[i] > key DO
A[i+1] ← A[i]
i ← i - 1
END WHILE
A[i+1] ← key
END FOR
def insertion_sort(A):
n = len(A)
for j in range(1, n):
key = A[j]
i = j - 1
while i >= 0 and A[i] > key:
A[i + 1] = A[i]
i -= 1
A[i + 1] = key
return A
Read a text string and output the frequency of each vowel (a, e, i, o, u), ignoring case.
INPUT text
text ← LOWERCASE(text)
count_a ← 0
count_e ← 0
count_i ← 0
count_o ← 0
count_u ← 0
FOR each ch IN text DO
IF ch = 'a' THEN
counta ← counta + 1
ELSE IF ch = 'e' THEN
counte ← counte + 1
ELSE IF ch = 'i' THEN
counti ← counti + 1
ELSE IF ch = 'o' THEN
counto ← counto + 1
ELSE IF ch = 'u' THEN
countu ← countu + 1
END IF
END FOR
OUTPUT "a:", counta, " e:", counte, " i:", count_i,
" o:", counto, " u:", countu
def count_vowels(text):
text = text.lower()
counts = {'a':0, 'e':0, 'i':0, 'o':0, 'u':0}
for ch in text:
if ch in counts:
counts[ch] += 1
return counts
Given a sorted list of distinct integers and a target value, determine whether the target occurs in the list using a recursive binary‑search algorithm.
FUNCTION binary_search(A, target, low, high) RETURNS BOOLEAN
IF low > high THEN
RETURN FALSE
END IF
mid ← (low + high) DIV 2
IF A[mid] = target THEN
RETURN TRUE
ELSE IF target < A[mid] THEN
RETURN binary_search(A, target, low, mid-1)
ELSE
RETURN binary_search(A, target, mid+1, high)
END IF
END FUNCTION
def binary_search(A, target, low, high):
if low > high:
return False
mid = (low + high) // 2
if A[mid] == target:
return True
elif target < A[mid]:
return binary_search(A, target, low, mid-1)
else:
return binary_search(A, target, mid+1, high)
| Exam Requirement | What to Include | How It Relates to Stepwise Refinement |
|---|---|---|
| AO1 – Knowledge & Understanding | Define stepwise refinement, list its stages, give pseudocode conventions. | Shows you can describe the process and its purpose. |
| AO2 – Application | Provide a correct, fully refined algorithm (Level 3) and analyse its time/space complexity. | Demonstrates you can apply the technique to a new problem. |
| AO3 – Evaluation | Discuss advantages (modularity, testing) and limitations (over‑engineering, time‑consuming for very small problems). Suggest alternative design methods (e.g., bottom‑up design, flow‑chart first). | Shows critical evaluation of the method. |
| Keyword | Purpose |
|---|---|
| IF … THEN … END IF | Conditional selection. |
| ELSE IF … THEN … | Additional conditions. |
| FOR i ← start TO end DO … END FOR | Count‑controlled loop. |
| WHILE condition DO … END WHILE | Pre‑test loop. |
| REPEAT … UNTIL condition | Post‑test loop. |
| FUNCTION / PROCEDURE | Define reusable blocks. |
| Class | Typical Example |
|---|---|
| O(1) | Accessing an array element by index. |
| O(log n) | Binary search, balanced tree lookup. |
| O(n) | Linear search, single pass over a list. |
| O(n log n) | Merge sort, heap sort. |
| O(n²) | Insertion sort, bubble sort, naïve matrix multiplication. |
When refining algorithms that manipulate binary data (e.g., bit‑wise masks, colour conversion), include a sub‑task that explains the representation before the actual computation.
Design a query‑building algorithm using stepwise refinement:
Use refinement to design a simple Caesar‑cipher encryption routine, then evaluate its security weaknesses (e.g., susceptibility to frequency analysis).
After presenting a refined algorithm, discuss possible ethical implications such as data privacy, bias, or environmental impact, linking back to the design choices made.
Your generous donation helps us continue providing free Cambridge IGCSE & A-Level resources, past papers, syllabus notes, revision questions, and high-quality online tutoring to students across Kenya.