Teachers' Portal  /  A-Level Computer Science 9618  /  Software development  /  State-transition diagrams
Lesson pack · A-Level Computer Science 9618 · 12.2 · AS Level

State-transition diagrams

Every input, a new state. Some programs do not run from start to finish: they wait, react to an event, and wait again.

Student lesson Lab, full screen
At a glance

The shape of the lesson

Topic
Software development
Syllabus reference
Cambridge International AS and A Level Computer Science 9618, 12.2
Level
AS Level
Duration
45 minutes, lab-led; stretches to a 60 minute block (see the contingency notes)
Position in topic
Lesson 3 of 5 in Software development; follows Structure charts; leads into Types of error and testing methods
Central model
Fig. 1: the alarm starts Disarmed; locking arms it; opening a door while armed sounds the siren; unlocking always disarms it
Cooperative structure
Assessment
Stage 1 check and the exam-style plenary from the student lesson, plus the worksheet as the exit task
Learning objectives

By the end of the lesson, learners can

Section by section
  • 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.
Key points to leave on the board
  • 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.
The core visual model

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.

State-transition diagram for a car alarm DisarmedArmedSounding lock unlock door opened / siren on unlock / siren off start
Fig. 1: the alarm starts Disarmed; locking arms it; opening a door while armed sounds the siren; unlocking always disarms it
Lesson sequence

Forty-five minutes, phase by phase

TimePhaseWhat happens in the roomGrouping
0 to 5 minHook: predictOpen 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 minTeach and check: States and transitionsFollow Fig. 1 with your finger.Whole class, then pairs
13 to 21 minTeach and check: Tables and tracesA 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 minTeach and check: From diagram to codeA 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 minCheckThe 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 minPlenaryThe 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 minExit and homeworkSet the worksheet below (6 questions, 17 marks). Learners self-assess against the objectives before they leave.Individual
Timing and contingency

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.

Running the cooperative task

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.

Examiner traps to pre-empt

What to head off, and how

Trap learners fall intoTeaching 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.
Worksheet

State-transition diagrams: worksheet

6 questions, 17 marks. Written in the style of the papers; no past paper question is reproduced.

NameClassDate
Q1 · recall[2 marks]

State the purpose of a state-transition diagram.

Q2 · trace[3 marks]

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.

Q3 · apply[4 marks]

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.

Q4 · explain[2 marks]

Explain how a start state and a halting state are shown on a state-transition diagram.

Q5 · write[4 marks]

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.

Q6 · analysis[2 marks]

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
Q1 · 2 marks
  • 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.
Q2 · 3 marks
  • 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.
Q3 · 4 marks
  • Off, press, Dim; Dim, press, Bright; Bright, press, Off.
  • Off, hold, Off (or no change).
  • Dim, hold, Off.
  • Bright, hold, Off.
Q4 · 2 marks
  • 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.
Q5 · 4 marks
  • 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.
Q6 · 2 marks
  • 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".
Quiz

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.

Q11 mark

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
Q21 mark

The music player in the figure receives the inputs play, pause, play, stop, in that order. What is its final state?

State-transition diagram for a music player StoppedPlayingPausedOff play / music on stop / music off pause / music off play / music on power start
  • AStopped
  • BPlaying
  • CPaused
  • DOff
Q31 mark

Which state in the figure is a halting state, and how can you tell?

State-transition diagram for a music player StoppedPlayingPausedOff play / music on stop / music off pause / music off play / music on power start
  • 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
Q41 mark

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.

State-transition diagram for a music player StoppedPlayingPausedOff play / music on stop / music off pause / music off play / music on power start
  • APlaying | pause | music off | Paused
  • BPaused | pause | music off | Playing
  • CPlaying | music off | pause | Paused
  • DStopped | play | none | Playing
Q51 mark

The music player in the figure receives the inputs play, pause, stop, play, in that order. What is its final state?

State-transition diagram for a music player StoppedPlayingPausedOff play / music on stop / music off pause / music off play / music on power start
  • APlaying
  • BStopped
  • CPaused
  • DOff
Q61 mark

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?

State-transition diagram for a music player StoppedPlayingPausedOff play / music on stop / music off pause / music off play / music on power start
  • 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
Q1: A

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.

Q2: A

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.

Q3: A

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.

Q4: A

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.

Q5: A

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.

Q6: A

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

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.

Also for this topic

Everything else you can use

Original work by the TheLucidSTEM team. The worksheet items are written in the style of the papers; no past paper question is reproduced.
Previous lessonStructure charts