Cameroon GCE O-Level Computer Science study materials
Cameroon GCE O-Level Computer Science study resources

Cameroon GCE O-Level Computer Science: Problem Solving and Algorithm Design: Pseudocode, Flowcharts and Program Logic

Cameroon GCE O-Level Computer Science · Work through your exam, one topic at a time.

All guide sections

Problem Solving and Algorithm Design: Pseudocode, Flowcharts and Program Logic

Problem solving and algorithm design tests whether you can express a solution precisely: pseudocode, flowcharts, and the logic of sequence, selection and iteration. Expect to complete or correct an algorithm, draw standard symbols, and dry-run code using a trace table.

Pseudocode conventions

Use the left arrow for assignment, = or == for comparison, and keywords in capitals: START/STOP, INPUT, OUTPUT, IF…THEN…ELSE…ENDIF, WHILE…ENDWHILE, REPEAT…UNTIL, FOR…NEXT, plus MOD and DIV. Indent loop and selection bodies so the structure is visible.

Flowchart symbols

Oval = terminator (start/stop); parallelogram = input/output; rectangle = process; diamond = decision with one entry and two exits, labelled Yes and No; arrow = direction of flow; circle = connector to another page.

Control constructs and standard algorithms

Sequence executes statements in order. Selection chooses a path (IF, or CASE for many options). Iteration repeats: a FOR loop when the count is known in advance, WHILE when the test is at the top so the body may run zero times, REPEAT…UNTIL when the body must run at least once. Learn linear search (checks each item in turn, works on unsorted data), binary search (repeatedly halves a sorted list, much faster but needs sorted data) and bubble sort (compares adjacent pairs, swapping until a pass makes no swaps).

Worked example

total ← 0 FOR i ← 1 TO 5 IF i MOD 2 = 0 THEN total ← total + i NEXT i OUTPUT total

Trace: i = 1, remainder 1, skip. i = 2, remainder 0, total becomes 2. i = 3, skip. i = 4, total becomes 6. i = 5, skip. Output 6 - the sum of the even values 2 and 4. The reasoning is that MOD returns the remainder, so the test selects even numbers only.

Traps

MOD gives the remainder and DIV the whole-number quotient, so swapping them changes the answer. A FOR loop from 1 to 5 runs its body five times, not four. A WHILE may execute zero times; a REPEAT always executes once. Do not write total = total + i when the convention uses the assignment arrow. A decision box has two exits, never three.