7 Algorithm design and problem-solving

Show All Section Notes
Test yourself on Algorithm design and problem-solving 13 questions — drag-to-order, code completion, matching and multiple choice.
Start the quiz

Structure Diagrams

Watch this lesson Video 7.3 · 6:41 · Decomposing a system into sub-systems — and describing each by what goes in and out

1. Top-Down Design

Top-Down Design is the process of breaking a main problem into smaller parts (sub-problems) until each part is simple enough to be solved. A Structure Diagram is the visual tool used to show this hierarchy.

2. Example: Smart Alarm Clock System

Notice how the main system is decomposed into three main modules, which are then broken down further.

Smart Alarm Clock
Set Alarm
Input Time
Check Time
Compare to Current
Trigger Alarm
Sound Buzzer

2b. Describing a Sub-system: Input, Process, Output

Decomposing a system produces sub-systems, and the exam does not usually stop at naming them. It asks you to describe each one in terms of its inputs, its processes and its outputs — because that is what turns a box on a diagram into something a programmer could actually build.

Sub-system Inputs Processes Outputs
Set Alarm Hours and minutes entered by the user Validate the time is in range; store it in memory Confirmation shown on the display
Check Time Current time from the clock; stored alarm time Compare the two values A signal when they match
Trigger Alarm The match signal; the volume setting Start the sound; begin the snooze timer Buzzer sounds; display flashes
Why this is the useful form. Notice that one sub-system's output becomes the next one's input — Check Time produces a signal, and Trigger Alarm consumes it. Writing the IPO for each sub-system is how you find out whether your decomposition actually joins up. If a sub-system needs an input that nothing produces, the decomposition is incomplete, and you have discovered that on paper rather than halfway through writing the program.

3. Key Rules for Structure Diagrams

  • Hierarchy: The "Parent" module is at the top; "Children" modules are below.
  • No Logic: Unlike flowcharts, structure diagrams do not show decisions (IF) or loops (WHILE). They only show the components of the system.
  • Modularization: Each box represents a discrete task that could be written as a separate subroutine (function/procedure).

4. Advantages of Modular Design

Easier Debugging: It is easier to find and fix an error in a small module of 10 lines than in a program of 1,000 lines.
Collaboration: Different programmers can work on different modules at the same time.
Reusability: Once a module is written (e.g., a "Calculate Tax" module), it can be used in other programs.
Maintenance: Modules can be updated or replaced individually without breaking the entire system.
⚠️ Exam Tip: If an exam asks you to "Complete a structure diagram," remember to check the levels. Ensure the new module you add is a sub-task of the module directly above it.