Lite / Discovering How the World Works / Week 17
Flowcharts: drawing a decision
Engineers often draw a machine's 'brain' before writing a single line of code. What does that drawing look like?
Why should I care?
A flowchart lets a whole team (engineers, clients, testers) see a machine's decisions at a glance and spot missing cases before anything is built. It's the bridge between a client's words and working code.
- Read and draw flowcharts using start/end, process and decision shapes.
- Count the different paths through a flowchart.
- Test a flowchart by choosing inputs that follow every path.
Predict
The smart fan's flowchart asks up to three yes/no questions and can end in OFF, LOW or HIGH. How many different paths are there from start to finish?
- 3
- 4
- 8
Guess first, then reveal
4. Nobody home → OFF. Someone home but cool → OFF. Hot with the window open → LOW. Hot with the window shut → HIGH. Two different paths both lead to OFF, so there are more paths than outcomes.
Discover
Your job is tester. Choose inputs that send the fan down all four paths, ticking each off in the test log. What is the fewest number of runs that can test every path?
What the interactive shows (text version)
The decision runner lists the fan's flowchart steps and a test log of its four paths: nobody home → OFF; cool enough → OFF; hot, window open → LOW; hot, window shut → HIGH. Each run through the flowchart ticks off the path it took, so you can see which paths still need testing.
Watch (optional)
Watch for: Watch for how an algorithm is a sequence of steps and decisions, the same thing a flowchart draws.
Shows how a step-by-step recipe of decisions and repeats lets a machine solve a problem such as sorting.
“Intro to Algorithms: Crash Course Computer Science #13” by CrashCourse (opens YouTube; streaming video uses a lot of data)
The video is optional. Everything you need is in this lesson's text.
Understand
Three shapes
- Rounded box (terminator): start or end.
- Rectangle (process): do something, like 'read the sensors' or 'turn the fan on'.
- Diamond (decision): a yes/no question with two arrows out, one labelled yes and one no.
Arrows show the order. Follow them with your finger and you're running the machine's program by hand.
Paths, not just outcomes
Each decision splits the path in two. A path is one complete route from start to end. Different paths can reach the same outcome (two ways to get OFF), and a good test plan tries every path, not just every outcome, because a mistake can hide on a path you never walked.
Loops: going round again
A real controller doesn't stop at 'end'. An arrow goes back to 'read the sensors', so the machine checks again and again. That's a loop. In the next lesson, you'll see machines that also remember where they are in a sequence.
Explain it another way
Intuitive
A flowchart is like a 'choose your own adventure' book: each diamond is a page that says 'if yes, turn to page 12; if no, turn to page 20.'
Technical
A flowchart is a directed graph of process and decision nodes. A test suite with path coverage exercises every route from entry to exit. Here, each decision only appears on some paths, so 4 tests cover all paths rather than 2³ = 8.
Applied
Medical devices, lifts and traffic lights are designed with flowcharts or state diagrams, and testers write one test case per path, often hundreds of them.
Worked example 1
Design inputs that test each fan path once.
- Nobody in the room (any temperature): OFF. 2. Someone in, 22 °C: OFF. 3. Someone in, 30 °C, window open: LOW. 4. Someone in, 30 °C, window shut: HIGH. Four runs cover all four paths.
Common mix-ups
If every outcome has been seen, the flowchart is fully tested.
✓ Different paths can lead to the same outcome. Test every path.
Practice
Practice, not a test. Answers are checked on our server; a wrong answer gets a hint and another try. Nothing is saved.
Apply it
Draw a flowchart for an automatic school-bag checker: is it a school day? Is it PE day (then check for kit)? Is it raining (then check for a coat)? Count its paths and write one test for each.
Reflect
What's one advantage of drawing a flowchart before writing code, and one thing a flowchart can't show you?
Write your answer on paper or in your own notes. Lite never stores what you write.