Theory Notes/💻 Topic 1: Solution Development/12.1.4
12.1.4Grade 12

Consolidation: Algorithms, 2D Arrays & Efficiency

The Grade 12 consolidation content — searching, sorting, two-dimensional arrays and recursion — plus the efficiency arguments the memo expects you to be able to make.

AlgorithmHow it worksRequires
Linear searchCheck each element in turn; stop when foundNothing
Binary searchHalve the range each stepA SORTED array
Bubble sortSwap adjacent out-of-order pairs, repeatedlyNothing
Selection sortFind the max/min of the rest, swap it into placeNothing

Binary search is dramatically faster than linear search, but only because the array is sorted — say so when asked to justify it. Selection sort does at most one swap per pass; bubble sort may do many.

Example

// Two-dimensional array: rows = learners, columns = subjects var marks: array[1..3, 1..4] of Integer; r, c, total: Integer; begin for r := 1 to 3 do begin total := 0; for c := 1 to 4 do total := total + marks[r, c]; WriteLn('Learner ', r, ' average: ', (total / 4):0:1); end; end.

The outer loop picks the row, the inner loop walks that row's columns. Swapping them gives you column totals instead — read the question carefully to see which is wanted.

Recursion
A routine that calls itself. Needs a base case that stops it, and a recursive case that moves towards the base case.
Sentinel / flag
A Boolean that records whether something was found, so the loop can stop early.
Efficiency argument
Fewer comparisons and fewer passes. 'It's faster' scores nothing without the reason.

💡 Exam Tip

In a for-loop the counter is read-only inside the loop body — assigning to i is a compile error, and a favourite exam trap.