1. Stepwise Refinement & Structure Charts
Algorithm design often starts with a complex problem. Stepwise refinement is the process of breaking this problem down into smaller, more manageable sub-problems. This is also known as decomposition. We repeat this process until each sub-problem is simple enough to be represented as a single program module (like a procedure or function). A structure chart is a diagram that visualises this decomposition. It shows the overall architecture of the solution, including the different modules, their hierarchy (which module calls which), and the data passed between them (parameters). It is a top-down design tool, focusing on what needs to be done, not how it is done.
Key term
Examiner insight
Common pitfall
Worked example 16 marks
A program is required to read the marks for a class of 30 students. It must calculate the average mark, and then count and display the number of students who scored above the average. Decompose this problem and represent the solution using a structure chart.
- 1
Step 1: Decompose the main problem. The top-level module could be 'Process Student Marks'.
- 2
Step 2: Identify the main sub-tasks. These are: reading the marks, calculating the average, and counting students above average.
- 3
Step 3: Further decomposition. 'Calculate Average' needs the marks and the count of students. 'Count Above Average' needs the marks and the calculated average.
- 4
Step 4: Draw the structure chart. The root is 'Process Student Marks'. This main module calls three sub-modules in sequence: 'ReadMarks', 'CalculateAverage', and 'CountAboveAverage'.
- 5
Step 5: Show parameter passing. 'ReadMarks' passes the array of marks up to the main module. The main module passes the marks array down to 'CalculateAverage' and 'CountAboveAverage'. 'CalculateAverage' passes the calculated average up to the main module. The main module passes this average down to 'CountAboveAverage'. 'CountAboveAverage' passes the final count up to the main module, which would then handle the output.
- 6
Step 6: Refine the chart with symbols. Use rectangles for modules. Use arrows with an empty circle for data parameters (e.g., `MarksArray`, `AverageMark`). The final chart shows 'ProcessStudentMarks' at the top, with calls to 'ReadMarks', 'CalculateAverage', and 'CountAboveAverage' below it, with arrows indicating the flow of parameters like `StudentMarks` and `Average` between them.
Recap
- Stepwise refinement breaks a large problem into smaller sub-problems.
- Structure charts are a visual representation of the modular design of a program.
- They show the hierarchy of modules and the parameters passed between them.
- A rectangle represents a module (procedure or function).
- An arrow with a circle at the end represents a parameter being passed.
- Structure charts are for design; they do not show logic like loops or decisions.
Quick check
- What is the primary purpose of a structure chart?1 mark
- What is the name of the design process that structure charts are based on?1 mark