ALGORITHM DEVELOPMENT.
Developing an algorithm that solves a specific problem can be a complex task. Systematic or logical approach is used to reduces the complex task into a simple one. One of the systematic approaches that can be used for algorithm development is based on the technique of stepwise refinement. This technique requires the main steps that solve the whole problem be developed, afterwards, each of the steps would be refined or split into small steps.
The diagram below illustrates further:
The big rectangle represents the particular problem to be solved, while each of the four rectangles represents the four main steps that solve the problem.
On each of the main steps, we refine it into small steps.
The diagram above illustrates that small steps a, b, c, d, e, f, g and h are the refinement of the main step ‘a’. Steps ‘b’, ‘c’ and ‘d’ can be refined in similar manner.
A particular problem can have different algorithms that solve the same problem.
Step-wise refinement process:
- Level 0: Initial solution with high-level steps
- Level 1: Refine the solution by adding more details
- Level 2: Further refine the solution by introducing loops and conditional statements
- Level 3: Final refinement with input validation and error handling
The final algorithm is more detailed, efficient, and robust.
Examples of Algorithm Development
Problem 1:
Develop an algorithm to calculate the average grade of a student given a list of grades.
Solution:
Main step:
1. Get the list of grades (Input)
2. Calculate the average grade (Processing)
3. Print the average grade (Output)
Using the process of Step-wise refinement, we can refine the steps as follows:
1. Request list of grades:
Ask for X,
Y and
for Z
2. Process average grade:
Calculate total= X+Y+Z
Total list= 3
Calculate Average= X+Y+Z / 3= ?
3. Display/Print average grade:
Display Average
In the above algorithm; Step 1 requires input of data, therefore we refine it into 3 smaller steps. Each step is used to request for one of the input data. As step 2 requires calculation of 3 results, which are sum and count, therefore we refine it into 3 steps. And step 3 requires the display of result.
Next topic:
1 comment