Worked example · Computer Science · Year 8 · Intermediate

Tracing and Debugging a River Flood Warning Flowchart

DCF: Data and computational thinking → Problem-solving and modelling · LNF: Numeracy → Logical reasoning

What this is

A complete model response and answer key for the cover teacher and for marking. Headline answers: in Step 1, the faulty flowchart fails at 04:00 (outputs RED instead of AMBER) and 07:00 (outputs GREEN instead of AMBER). In Step 2, Diamond D2 must be changed from OR to AND (level >= 3.2 AND rain >= 15), and Diamond D3 must be changed from < to >= (level >= 2.4). In Step 3, the fixed outputs are 04:00 = AMBER, 06:00 = RED, 07:00 = AMBER, Boundary test A (2.4 m) = AMBER, Boundary test B (2.2 m) = GREEN.

Step 1: Dry-run the trainee’s faulty flowchart

Time level (m) rain (mm/hr) D1:
level < 2.0?
D2:
level >= 3.2 OR rain >= 15?
D3:
level < 2.4?
Faulty output Expected output (spec)
01:00 1.4 2 Yes - - GREEN GREEN
02:00 1.7 5 Yes - - GREEN GREEN
03:00 1.9 11 Yes - - GREEN GREEN
04:00 (mismatch) 2.6 18 No Yes (rain 18 >= 15) - RED AMBER
05:00 3.3 19 No Yes - RED RED
06:00 3.4 16 No Yes - RED RED
07:00 (mismatch) 2.8 9 No No No (2.8 is not < 2.4) GREEN AMBER
08:00 1.8 3 Yes - - GREEN GREEN

Follows the faulty rules strictly without guessing, recording skipped diamonds with a dash and isolating the exact two hours (04:00 and 07:00) where the outputs diverge from the specification. Evidences criterion 1.

Step 2: Diagnose and fix the two logic bugs

Diamond Faulty condition Why it caused a wrong alert (quote the hour and numbers) Corrected condition
Diamond D2
(Red check)
level >= 3.2 OR rain >= 15 Using OR meant only one condition needed to be true. At 04:00, rainfall was 18 mm/hr (>= 15), so D2 answered Yes and triggered a false RED evacuation even though the river was only 2.6 m (below 3.2 m). level >= 3.2 AND rain >= 15
Diamond D3
(Amber check)
level < 2.4 The inequality sign was backwards. At 07:00, the river was 2.8 m (above the 2.4 m Amber threshold), so 2.8 < 2.4 evaluated to No and output GREEN, missing a real flood warning. level >= 2.4

Explains the logical flaw in both operators by quoting the exact hourly values from the trace table and gives the precise Boolean and relational corrections. Evidences criteria 2 and 3.

Step 3: Re-test with the corrected diamonds (including two boundary tests)

Test case level (m) rain (mm/hr) D1:
level < 2.0?
Fixed D2:
level >= 3.2 AND rain >= 15?
Fixed D3:
level >= 2.4?
Fixed output
04:00 storm shower 2.6 18 No No (2.6 is not >= 3.2) Yes (2.6 >= 2.4) AMBER
06:00 peak flood 3.4 16 No Yes (both true) - RED
07:00 high river 2.8 9 No No (neither true) Yes (2.8 >= 2.4) AMBER
Boundary test A 2.4 10 No No Yes (2.4 >= 2.4) AMBER
Boundary test B 2.2 10 No No No (2.2 is not >= 2.4) GREEN

Verifies that fixing both diamonds resolves the 04:00 and 07:00 errors, preserves the 06:00 Red alert, and handles the 2.4 m boundary and the 2.0 m to 2.4 m band accurately. Evidences criterion 3.

Step 4: Write the corrected pseudocode

INPUT level, rain IF level < 2.0 THEN OUTPUT "GREEN: Normal" ELSE IF level >= 3.2 AND rain >= 15 THEN OUTPUT "RED: Evacuate" ELSE IF level >= 2.4 THEN OUTPUT "AMBER: Flood warning" ELSE OUTPUT "GREEN: Normal" END IF

(b) Why RED must be checked before AMBER: Any river level that is >= 3.2 is also automatically >= 2.4. If the program checked level >= 2.4 first in an IF / ELSE IF structure, a severe flood of 3.4 m with 16 mm/hr of rain would match the first branch, output AMBER: Flood warning, and skip the RED: Evacuate branch altogether.

Uses clean, indented selection statements and explains why mutually overlapping conditions must be ordered from most restrictive (Red) to broader threshold (Amber). Evidences criterion 4.

If you finish early: answers

Because any reading with level >= 3.8 is also >= 3.2 and >= 2.4, the SEVERE RED check must go before the normal RED and AMBER checks (either right at the top or immediately after IF level < 2.0):

INPUT level, rain IF level < 2.0 THEN OUTPUT "GREEN: Normal" ELSE IF level >= 3.8 THEN OUTPUT "SEVERE RED: Danger to life" ELSE IF level >= 3.2 AND rain >= 15 THEN OUTPUT "RED: Evacuate" ELSE IF level >= 2.4 THEN OUTPUT "AMBER: Flood warning" ELSE OUTPUT "GREEN: Normal" END IF

Why this response is secure