Programming and Algorithms
Domain focus
Programming and Algorithms tests problem decomposition, pseudocode and flowcharts, control structures, variables and tracing. You must show the logic step by step, not just state the output.
Core rules and concepts
- An algorithm is a finite ordered set of steps; a flowchart uses standard symbols: oval for start and end, parallelogram for input and output, rectangle for process, diamond for decision.
- Sequence runs steps in order; selection uses IF/ELSE or CASE; iteration uses FOR, WHILE or REPEAT.
- A variable is a named storage location; declare its type (integer, real, string, Boolean). Assignment uses
←or=, while comparison uses=or==depending on syntax. - Dry running uses a trace table: columns for variables and output, one row per step.
- Errors: syntax (grammar), logic (wrong result), runtime (fails while running, such as division by zero).
Worked example
Find the sum of 1 to 5.
total ← 0
FOR i ← 1 TO 5
total ← total + i
ENDFOR
OUTPUT total
Trace: start total=0; i=1 total=1; i=2 total=3; i=3 total=6; i=4 total=10; i=5 total=15. Output 15. Reasoning: the loop runs five times, adding the current counter to the running total; the final value is the sum, not the last counter value.
Traps that cost marks
Confusing assignment with comparison; forgetting to initialise total; an off-by-one loop that runs 4 or 6 times; swapping the decision branches; ignoring data types such as integer division versus real division; and calling a wrong-output program a syntax error.