5.3 - Representing Algorithms with Flow Diagrams
The purpose and basic structure of flow diagrams
Flow diagrams provide a visual way to represent algorithms, using shapes connected by arrows to show the steps in a process. Each shape in a flow diagram represents a specific command or action. This visual format helps illustrate the flow of actions from start to finish, with arrows indicating the direction of the process.
The different shapes used for commands in flow diagrams
Each shape in a flow diagram represents a specific type of command or action. Using the correct shape ensures the diagram is clear and follows standard conventions.
Common shapes and their meanings
| Shape | Name | Purpose |
|---|---|---|
| Rounded rectangle | Start/Stop | Marks the beginning (Start) or end (Stop) of the algorithm. |
| Rectangle | Process | Represents general instructions, calculations, or actions, such as "Add 5 to total". |
| Diamond | Decision | Shows a yes/no question or choice, where the path splits based on the answer. |
| Parallelogram | Input/Output | Indicates data being entered (input) or displayed (output), like "Enter password" or "Display message". |
| Arrow | Connector | Links shapes together and shows the direction to follow; multiple arrows can enter or leave a shape. |
These shapes help distinguish between different parts of the algorithm, making it easier to spot where decisions are made or data is handled.
How to interpret decision boxes and arrows
Decision boxes (diamonds) are key for showing choices in a flow diagram. They usually contain a question with two possible outcomes, labelled "Yes" or "No", and arrows lead to different paths based on the answer.
Arrows connect all elements, creating a flow that might include straight sequences or loops back to earlier steps. Always label arrows from decision boxes to clarify the paths. This setup allows for branching (where the process splits) and iteration (repeating steps until a condition changes).
Example of a flow diagram for a security system
Flow diagrams can illustrate real-world algorithms, such as a simple security system that checks sensors and responds accordingly. This example shows how shapes combine to create a complete process, including a loop for ongoing monitoring.
Key elements in the security system flow diagram
- Start - The diagram begins with a rounded rectangle labelled "Start".
- Decision - A diamond asks, "Have any sensors been set off?" This splits into two paths:
- Yes path - Leads to a sequence of outputs – a parallelogram for "Display red light", followed by another for "Play warning sound", then to a rounded rectangle "Stop".
- No path - Goes to a parallelogram "Display green light", then a rectangle "Wait 5 seconds". An arrow loops back to the decision diamond, creating iteration (repeating the check until sensors are triggered).
- Iteration explanation - The loop ensures the system continuously monitors sensors while showing a green light, only breaking when the decision changes to "Yes".
This structure demonstrates sequence (steps in order), selection (decision-based paths), and iteration (repeating actions), which are fundamental concepts in algorithms.