Structure Charts & State-Transition Diagrams
9618 AS Computer Science
Structure charts and state-transition diagrams are essential modelling tools used in the design stage of program development. They help programmers visualise how modules are interrelated and how systems move between different states based on inputs. These tools focus on WHAT the program does, not HOW it does it!
A structure chart is a modelling tool used in the design stage of program development. It helps to decompose a problem into smaller, manageable sub-tasks, representing each as a module.
A structure chart is a modelling tool used in program design to decompose a problem into a set of sub-tasks. The structure chart shows the hierarchy of the different modules and how they connect and interact with each other.
| Key Purpose | Description |
|---|---|
| Decomposition | Breaks down complex problems into smaller, manageable sub-tasks |
| Visualise Relationships | Shows how modules are interrelated and interface with each other |
| Parameter Passing | Shows what data is passed between modules (parameters and return values) |
| Interface Design | Shows the interface between modules (the variables/parameters) |
| Documentation | Provides clear documentation for program design |
Structure charts focus on WHAT the program does, not HOW it does it. They are used in the design stage to plan the program structure before writing actual code.
| Feature | Explanation |
|---|---|
| Top-down Design | Chart starts with main program and breaks into sub-modules |
| Decomposition | Each module represents a specific task or function |
| Module Boxes | Each module is shown as a box |
| Vertical Lines | Show control flow – which module calls which |
| Parameter Arrows | Arrows pointing into modules show data being passed in or returned |
| Stepwise Refinement | Each level adds more detail to the task above |
Remember: Each level of the structure chart is a refinement of the level above. The top level shows the main task, and each subsequent level breaks down the task into more detail.
| Symbol | Name | Description |
|---|---|---|
| Rectangle Box | Process/Module/Subroutine | Indicates the module/subroutine name |
| Vertical Line | Call Line | Shows the program flow path between modules (how they connect) |
| Diamond Shape | Selection | Shows where program may branch off onto different call lines (condition) |
| Semi-circular Arrow | Repetition | Indicates a process may be repeated (loop) |
| Arrow Type | Meaning | Description |
|---|---|---|
| Data Flow Arrow | Data being passed | Used to indicate where data is being passed between modules. Can be parameters passed to modules OR return values |
| Control Flow Arrow | Control signal/flag | Used to indicate where data passed is used to control the flow of the program. Usually a True/False flag passed as a return value |
| Double-headed Arrow | Updated variable | Shows that variable value is updated within the module |
| Solid Round End Arrow | Flag (Boolean) | Shows that value transferred is a flag (a Boolean value) |
Diamond = Decision - A diamond shape looks like a decision point where you can go different ways.
Semi-circle = Loop - The curved arrow going back reminds you of cycling/looping back to repeat.
Round end = Ready/Flag - The solid round end indicates a Boolean flag (True/False).
A simple structure chart for converting a temperature from Fahrenheit to Celsius. The top level shows the name for the whole task that is refined into three sub-tasks or modules shown on the next level.
Structure chart for a module that calculates the average of two numbers. Input numbers (parameters Number1 and Number2) are passed into the 'Calculate Average' sub-task and then the Average parameter is passed into the 'OUTPUT Average' sub-task.
Structure charts can show selection using a diamond-shaped box to show a condition that could be true or false.
The temperature conversion task can be extended to either convert from Fahrenheit to Celsius OR Celsius to Fahrenheit:
Structure charts can show repetition using a labelled semi-circular arrow above the modules to be repeated.
The temperature conversion task can be extended to repeat until the number 999 is input:
When drawing structure charts:
Draw a structure chart to input the radius of a sphere, calculate and output either the volume or surface area. The algorithm should repeat until a radius of zero is entered.
Once a structure chart has been completed, it can be used to derive a pseudocode algorithm:
DECLARE radius : REAL
DECLARE answer : REAL
DECLARE choice : STRING
A Finite State Machine (FSM) is a mathematical model of a machine that can be in one of a fixed set of possible states. One state is changed to another by an external input, this is called a transition.
A diagram showing the behaviour of an FSM is called a state-transition diagram. It shows how a system moves between different states based on inputs.
State-transition diagrams show:
| Element | Description |
|---|---|
| State | Circle labelled with a name (e.g., S1, S2) showing a situation the system can be in |
| Initial State | Starting point, indicated by an arrow with a black dot pointing to it |
| Transition | Arrow from one state to another, labelled with input and output |
| Input | Event or data that causes a transition (e.g., Button-Y pressed) |
| Output | Action or signal produced by a transition (e.g., Output-A) |
| Next State | The state the system moves into after the transition |
| Stopped State | Indicated by a double circle (halting state) |
Always identify the initial state before tracing through a state-transition diagram. Look for the arrow with a black dot pointing to a state - that's where you start!
Algorithm for unlocking a door using a three-digit entry code (259). If the door is unlocked with the correct three-digit code, the lock can be in four states:
Important: If an incorrect digit is input at any point, the door returns to the Locked state.
The double circle around the Unlocked state indicates that the lock halts in this state. The algorithm stops when the door is unlocked.
A state-transition table shows every state of a finite state machine (FSM), each possible input, and the state after the input.
| Column | Description |
|---|---|
| Current State | The state the system is currently in |
| Input | The event or data that triggers a transition |
| Output | The action or signal produced (if any) |
| Next State | The state the system moves to after the transition |
| Current State | Input | Output | Next State |
|---|---|---|---|
| Locked | 2 | none | Got2 |
| Locked | 0, 1, 3, 4, 5, 6, 7, 8, 9 | none | Locked |
| Got2 | 5 | none | Got25 |
| Got2 | 0, 1, 2, 3, 4, 6, 7, 8, 9 | none | Locked |
| Got25 | 9 | Unlock | Unlocked |
| Got25 | 0, 1, 2, 3, 4, 5, 6, 7, 8 | none | Locked |
A finite state machine can convert a positive binary integer into its two's complement negative equivalent. The FSM takes input one bit at a time, starting with the least significant bit.
Once a structure chart has been completed, it can be used to derive a pseudocode algorithm. Here's a complete example of a login system.
A program that asks a user to enter their username and password, checks if the password matches the stored password, and uses a counter to track attempts. After three failed attempts, access is denied.
| Identifier | Data Type | Description |
|---|---|---|
| Username | STRING | Stores the username entered by the user |
| Password | STRING | Stores the password entered by the user |
| StoredPass | STRING | The correct password stored in the system |
| NoAttempts | INTEGER | Counts the number of failed login attempts |
| LoginSuccess | BOOLEAN | Indicates whether the login was successful |
| Module | Type | Purpose |
|---|---|---|
| GetCredentials | PROCEDURE | Asks the user to input username and password |
| CheckPassword | FUNCTION | Compares input password with stored password and returns TRUE/FALSE |
| ShowAccessMessage | PROCEDURE | Displays success or failure message |
DECLARE Username : STRING
DECLARE Password : STRING
DECLARE StoredPass : STRING
DECLARE NoAttempts : INTEGER
DECLARE LoginSuccess : BOOLEAN
StoredPass ← "admin123"
NoAttempts ← 0
LoginSuccess ← FALSE
PROCEDURE GetCredentials()
OUTPUT "Enter username: "
INPUT Username
OUTPUT "Enter password: "
INPUT Password
ENDPROCEDURE
FUNCTION CheckPassword(P : STRING) RETURNS BOOLEAN
IF P = StoredPass THEN
RETURN TRUE
ELSE
RETURN FALSE
ENDIF
ENDFUNCTION
PROCEDURE ShowAccessMessage(Success : BOOLEAN)
IF Success = TRUE THEN
OUTPUT "Login successful"
ELSE
OUTPUT "Access denied"
ENDIF
ENDPROCEDURE
// Main program
WHILE NoAttempts < 3 AND LoginSuccess = FALSE
CALL GetCredentials()
LoginSuccess ← CheckPassword(Password)
IF LoginSuccess = FALSE THEN
OUTPUT "Incorrect password"
NoAttempts ← NoAttempts + 1
ENDIF
ENDWHILE
CALL ShowAccessMessage(LoginSuccess)
Answer:
Additional points for deeper understanding:
Answer:
Additional points for deeper understanding:
Answer Structure Chart:
Marks awarded for: main module (1), sub-modules (2), data flow arrows (2), correct connections (1)
Answer:
Additional points for deeper understanding:
Answer:
| Current State | Input | Output | Next State |
|---|---|---|---|
| S1 | Input-A | none | S2 |
| S1 | Input-B | none | S3 |
| S2 | Input-B | Output-X | S3 |
| S3 | Input-A | Output-Y | S4 |
One mark for each correct row
Answer:
Additional points for deeper understanding:
Answer:
Selection:
Repetition:
Marks: 3 for selection (symbol, description, example), 3 for repetition (symbol, description, example)
Answer:
Additional points for deeper understanding:
Answer:
Additional points for deeper understanding:
Answer:
Additional points for deeper understanding:
Structure Chart → A modelling tool used in program design to decompose a problem into a set of sub-tasks and show the hierarchy of modules.
Module → A self-contained unit of code that performs a specific task, represented as a box in a structure chart.
Decomposition → The process of breaking down a complex problem into smaller, manageable sub-tasks.
Parameter → A value passed to a module/procedure/function, shown by arrows in a structure chart.
Interface → The connection between modules, defined by the parameters passed between them.
Stepwise Refinement → The process of adding more detail to each level of a structure chart, with each level being a refinement of the level above.
Selection → A program structure where different paths are taken based on a condition, represented by a diamond shape in structure charts.
Repetition → A program structure where a set of statements is repeated, represented by a semi-circular arrow in structure charts.
Finite State Machine (FSM) → A mathematical model of a machine that can be in one of a fixed set of possible states.
State → A condition or situation of a system, represented as a circle in state-transition diagrams.
Transition → The movement from one state to another caused by an external input.
State-Transition Diagram → A diagram showing the behaviour of an FSM, including states, transitions, inputs, and outputs.
Initial State → The starting state of an FSM, indicated by an arrow with a black dot.
Halted/Stopped State → A state where the FSM stops, indicated by a double circle.
State-Transition Table → A table showing every state, each possible input, output, and the next state.
Data Flow Arrow → An arrow showing data being passed between modules in a structure chart.
Control Flow Arrow → An arrow showing a Boolean flag that controls program flow.
Call Line → A vertical line in a structure chart showing which module calls which.
| Structure Chart | State-Transition Diagram |
|---|---|
| Shows module hierarchy | Shows system states and transitions |
| Focuses on WHAT the program does | Shows HOW the system behaves |
| Used for decomposition | Used for modelling FSMs |
| Shows parameter passing | Shows input/output on transitions |
| Diamond = selection | Circle = state |
| Semi-circle = repetition | Double circle = halted state |
| Symbol | Structure Chart Meaning | State Diagram Meaning |
|---|---|---|
| Rectangle | Module/Process | — |
| Circle | — | State |
| Diamond | Selection/Condition | — |
| Double Circle | — | Halted State |
| Semi-circular Arrow | Repetition | — |
| Arrow with Black Dot | — | Initial State |
| Arrow (pointed) | Data/Control Flow | Transition |