Supply teacher deck · Computer Science · Year 8

Tracing and Debugging a River Flood Warning Flowchart

Slide 1 of 7
05:00

Slide 1 of 7 · Settling starter · Computer Science · Year 8

5 minutes

Tracing and Debugging a River Flood Warning Flowchart

During an autumn storm on the Afon Glyn, an automated river sensor sounded the village evacuation siren at 04:00 when the river had not flooded, and then stayed silent at 07:00 when water reached the car park.

While the register is called: write your name, class and date on your worksheet, then read section 1 of the stimulus sheet.

Starter question: At 04:00, the river level was 2.6 m and rainfall was 18 mm/hr. According to the official safety specification in section 1, which alert should have been sent: RED, AMBER or GREEN?

DCF: Problem-solving and modelling · LNF: Logical reasoning No computers needed · work on your sheet

Slide 2 of 7 · Today’s brief and key words · Computer Science · Year 8

5 minutes

How engineers find logic bugs: dry running

The program did not crash: it followed the trainee’s flowchart step by step, but the flowchart contained two logic errors. You will dry-run the flowchart with a trace table, fix the two decision diamonds, and write the corrected pseudocode.

AND vs OR

AND: true only when both conditions are true.
OR: true when at least one condition is true.

Comparison operators

< less than
>= greater than or equal to

Trace table

A row-by-row table that records every input, decision (Yes/No) and output to test an algorithm.

DCF: Problem-solving and modelling · LNF: Logical reasoning Look at the trainee’s flowchart in section 2 of the stimulus

Slide 3 of 7 · Step 1 · Trace the faulty flowchart

10 minutes

Step 1: Complete the trace table for the faulty flowchart

Test all 8 hourly readings from section 3 of the stimulus sheet through Diamonds D1, D2 and D3. Write Yes, No, or a dash (-) if a diamond is skipped.

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
01:00 1.4 2 Yes - - GREEN GREEN
04:00 2.6 18 No Yes - RED AMBER
DCF: Problem-solving and modelling · LNF: Logical reasoning Circle the two hours where Faulty output and Expected output do not match

Slide 4 of 7 · Step 2 · Diagnose and fix the two logic bugs

10 minutes

Step 2: Diagnose and correct Diamonds D2 and D3

Use your trace table from Step 1 to explain why the algorithm failed at 04:00 and 07:00, and write the exact corrected condition inside each decision diamond.

Diamond D2 (Red evacuation): needs BOTH high water (level >= 3.2) AND heavy rain (rain >= 15).

Diamond D3 (Amber warning): reached when the river is at least 2.0 m and not Red. It should trigger Amber when level is at or above 2.4 m.

DCF: Problem-solving and modelling · LNF: Logical reasoning Write the exact Boolean condition for each diamond

Slide 5 of 7 · Step 3 · Re-verify and write pseudocode

12 minutes

Step 3: Re-run the test cases and write pseudocode

First, re-trace rows 04:00, 06:00, 07:00 and a boundary test of level = 2.4, rain = 10 through your fixed diamonds. Then complete the IF / ELSE IF / ELSE pseudocode block in Step 4.

Pseudocode structure:

IF level < 2.0 THEN
    OUTPUT "GREEN: Normal"
ELSE IF ... THEN
    OUTPUT "RED: Evacuate"

DCF: Problem-solving and modelling · LNF: Logical reasoning Don’t forget END IF at the end of your selection block

Slide 6 of 7 · Partner check and extension

5 minutes

Check your pseudocode and boundary test

Swap sheets with your partner or check your own work against the success criteria box on your worksheet.

Key check 1: Does your pseudocode check level >= 3.2 AND rain >= 15 before checking level >= 2.4? Why does the order of those two checks matter?

Key check 2: Why did we use >= 2.4 rather than > 2.4?

DCF: Problem-solving and modelling · LNF: Logical reasoning Tick the success criteria you have met

Slide 7 of 7 · Plenary · Final answer check

3 minutes

Plenary: Summary of the fix

Check your completed worksheet against the summary below before handing it in.

Part Correct answer
Two failed hours in Step 1 04:00 (false RED evacuation, should be AMBER) and 07:00 (false GREEN, missed AMBER warning)
Fixed Diamond D2 level >= 3.2 AND rain >= 15
Fixed Diamond D3 level >= 2.4
Boundary test (2.4 m, 10 mm/hr) D1: No · D2: No · D3: Yes → AMBER: Flood warning
DCF: Problem-solving and modelling · LNF: Logical reasoning Hand in your worksheet · leave stimulus sheets on desks