Programming and Problem Solving
Domain scope
Programming and problem solving tests algorithm design, pseudocode, control structures, arrays, subprograms, debugging and tracing. You must read an algorithm and state its output or identify a logic error, not merely write syntax.
Core rules
- Sequence, selection and iteration are the three control structures. Every loop needs initialisation, a condition and an update that moves toward termination.
- Pseudocode conventions: assignment uses ← or =; input and output are explicit; indentation shows block structure.
- Arrays are indexed; state whether indexing starts at 0 or 1. A loop from 1 to n inclusive runs n times; from 0 to n−1 also runs n times.
- A function returns a value; a procedure performs an action. Parameters can be passed by value (copy) or by reference (address).
Worked example
Trace: total ← 0; FOR i ← 1 TO 4; total ← total + ii; ENDFOR; OUTPUT total. Reasoning: i=1 adds 1; i=2 adds 4, giving 5; i=3 adds 9, giving 14; i=4 adds 16, giving 30. The output is 30. The loop runs four times. A common error is to add i instead of ii, which gives 10.
Traps
- Off-by-one errors at loop boundaries.
- Integer division: 7/2 may be 3 in integer context, not 3.5.
- Changing a loop variable inside the body and breaking termination.
- Confusing pass-by-value with pass-by-reference when a procedure modifies a parameter.