The shape of the lesson
By the end of the lesson, learners can
- States and transitions: Follow Fig. 1 with your finger.
- Tables and traces: A state-transition table lists one row for each arrow.
- From diagram to code: A state-transition diagram converts directly into pseudocode.
- Circle: a state; double circle: halting state; arrow from a dot: start.
- Arrow label: input / output.
- Trace: from the start state, follow one arrow per input; no arrow means no change.
- Table: current state, input, output, next state; one row per arrow.
One picture every idea returns to
A state-transition diagram documents an algorithm or system whose behaviour depends on its current state and the next input (event). Each state is a circle. Each transition is an arrow from one state to another, labelled with the input that causes it and, after a slash, any output it produces: input / output. An arrow from a dot marks the start state; a double circle marks a halting (final) state. The same information can be written as a state-transition table.
Forty-five minutes, phase by phase
| Time | Phase | What happens in the room | Grouping |
|---|---|---|---|
| 0 to 5 min | Hook: predict | Open with the question in the title, Every input, a new state.. Some programs do not run from start to finish: they wait, react to an event, and wait again. Put the figure on the board: it is the one picture every idea in the lesson returns to. | Whole class, then pairs |
| 5 to 13 min | Teach and check: States and transitions | Follow Fig. 1 with your finger. | Whole class, then pairs |
| 13 to 21 min | Teach and check: Tables and traces | A state-transition table lists one row for each arrow. Model the worked example Trace a sequence on the board, one line at a time. Your turn: What is the final state of the keypad in Fig. 2 after the inputs wrong, wrong, wrong, correct? | Pairs |
| 21 to 30 min | Teach and check: From diagram to code | A state-transition diagram converts directly into pseudocode. Your turn: Using Fig. 1, what is the state and what is output after the inputs lock, door opened, lock, unlock? | Anticipation / Reaction Guide |
| 30 to 36 min | Check | The four Stage 1 questions from the student lesson, answered on mini whiteboards or by show of fingers. Re-teach the one most get wrong. | Individual, then whole class |
| 36 to 43 min | Plenary | The exam-style questions from Stage 2, one at a time: thirty seconds alone, then a random call. The feedback lines in the key give the examiner's wording. | Individual, random call |
| 43 to 45 min | Exit and homework | Set the worksheet below (6 questions, 17 marks). Learners self-assess against the objectives before they leave. | Individual |
Protect the parts that carry the learning
The sequence carries about fifty minutes of material, so the lab is driven by one student while the class predicts rather than explored freely. Times are a guide.
Protected: the check at 30 minutes. It is the only individual read on whether the key idea landed, and it is not cut.
Cut first if the build overruns: the last check in From diagram to code, never the check or the plenary.
In a 60 minute block: run worksheet questions 1 to 3 in class as a Rally Coach set and model both the hardest worked example and its check live.
Anticipation / Reaction Guide
Before the lesson, students mark five statements true or false. After the teaching they mark them again and justify any change of mind in one sentence each. The statements come from the examiner traps below.
The full structure, with its variations and the other twelve, is on the cooperative-learning page.
What to head off, and how
| Trap learners fall into | Teaching move that pre-empts it |
|---|---|
| Label every arrow with the input that causes it. | An arrow with no label, or a state with no way out when the system should continue, loses marks. |
| Do not confuse a state-transition diagram with a flowchart. | A flowchart shows the steps of a process in order; a state-transition diagram shows states and the inputs that move the system between them. |
State-transition diagrams: worksheet
6 questions, 17 marks. Written in the style of the papers; no past paper question is reproduced.
State the purpose of a state-transition diagram.
Using Fig. 1 of the lesson (the car alarm), give the state after each input and any output, for the inputs: lock, door opened, unlock, door opened.
A lamp has states Off, Dim and Bright. It starts Off. Pressing the button moves Off to Dim, Dim to Bright and Bright to Off. Holding the button for 3 seconds in any state turns it Off. Complete a state-transition table for the lamp.
Explain how a start state and a halting state are shown on a state-transition diagram.
A turnstile has states Locked and Unlocked, starting Locked. Input coin in Locked moves to Unlocked; input push in Unlocked moves to Locked. Other inputs cause no change. The current state is stored in the global variable State. Write a pseudocode procedure Turnstile(Event : STRING) that makes the transitions.
In Fig. 2 of the lesson, a user wants the keypad to unlock again 10 minutes after it reaches Locked. Describe the change to the diagram.
Answer key and marking notes
- To document an algorithm / system whose behaviour depends on its state.
- It shows the states, the inputs (events) that cause transitions between them, and any outputs.
- lock: Armed (no output); door opened: Sounding, output siren on.
- unlock: Disarmed, output siren off.
- door opened: no transition from Disarmed, so it stays Disarmed with no output.
- Off, press, Dim; Dim, press, Bright; Bright, press, Off.
- Off, hold, Off (or no change).
- Dim, hold, Off.
- Bright, hold, Off.
- The start state has an arrow pointing into it from a dot / from no other state.
- A halting state is drawn as a double circle; no transitions leave it.
- PROCEDURE Turnstile(Event : STRING) ... ENDPROCEDURE.
- CASE OF State (or IF on State) with a branch for each of Locked and Unlocked.
- "Locked" : IF Event = "coin" THEN State ← "Unlocked" ENDIF.
- "Unlocked" : IF Event = "push" THEN State ← "Locked" ENDIF, ENDCASE.
- Locked is no longer a halting state: draw it as a single circle.
- Add an arrow from Locked to 0 fails labelled with the input / event "10 minutes passed".
6 multiple-choice questions on this lesson
From the topic question bank. Assign them in the app for a marked score in your gradebook, or run the topic as a class game.
Which statement describes a state-transition diagram?
- AIt shows how a system responds to each input, depending on the state it is currently in
- BIt shows the modules of a program and the parameters passed between them
- CIt shows every step of a process in order, using decision boxes for choices
- DIt shows how the values of variables change while an algorithm is dry run
The music player in the figure receives the inputs play, pause, play, stop, in that order. What is its final state?
- AStopped
- BPlaying
- CPaused
- DOff
Which state in the figure is a halting state, and how can you tell?
- AOff, because it is drawn as a double circle
- BStopped, because an arrow comes into it from a dot
- CPaused, because no stop arrow leaves it
- DPlaying, because it has the most arrows
Which row of a state-transition table correctly describes one of the transitions in the figure? The columns are: current state, input, output, next state.
- APlaying | pause | music off | Paused
- BPaused | pause | music off | Playing
- CPlaying | music off | pause | Paused
- DStopped | play | none | Playing
The music player in the figure receives the inputs play, pause, stop, play, in that order. What is its final state?
- APlaying
- BStopped
- CPaused
- DOff
Testers find that pressing stop while the player in the figure is Paused does nothing. The designer wants stop to move it to Stopped, with no output. What change should be made to the diagram?
- AAdd an arrow from Paused to Stopped labelled stop
- BAdd an arrow from Stopped to Paused labelled stop
- CRedraw Paused as a double circle
- DAdd an arrow from Paused to Stopped labelled music off
Quiz key
A state-transition diagram documents a system whose behaviour depends on its current state and the next input: states are circles and transitions are labelled arrows. Modules and parameters are shown on a structure chart. Steps with decision boxes make a flowchart. Variable values during a dry run go in a trace table.
Stopped, then play: Playing; pause: Paused; play: Playing; stop: Stopped. Playing and Paused are states passed through on the way. Off needs the input power while Stopped, which never arrives.
A halting (final) state is drawn as a double circle, and no transitions leave it: that is Off. The arrow from a dot marks Stopped as the start state, not a halting state. Paused still has an arrow (play) leaving it. The number of arrows has nothing to do with halting.
The arrow from Playing to Paused is labelled pause / music off: current state Playing, input pause, output music off, next state Paused. The second row runs the arrow backwards. The third swaps the input and the output. The fourth leaves out the output music on that the play arrow produces.
play: Playing; pause: Paused. There is no stop arrow leaving Paused, so stop changes nothing and the player stays Paused. Then play: Playing. Stopped assumes stop works from any state, and after it the final play would still lead to Playing. Paused ignores the last input. Off needs the input power.
A new transition needs an arrow from the current state (Paused) to the next state (Stopped), labelled with its input, stop; with no output, nothing follows a slash. An arrow from Stopped to Paused points the wrong way. A double circle would make Paused a halting state, so even play would stop working. music off is an output, not the input that triggers the transition.
Slides for this lesson
A projectable deck for every pack is on the way. Until then, present the student lesson full screen: its sections, figure and lab tabs follow the same order as the plan above.