Algorithm design 
 
 
An algorithm is a specification of a method to solve a problem. Several tecniques can be used to develop an algorithm to solve a given problem.
 
 
 
 
I)  Stepwise refinement and top-down design
 

    One method of solving a problem is by stating the problem and then subdividing the problem into subproblems. Each subproblem, in turn, can be treated as another problem, so it can be further divided into smaller subproblems. The process is repeated until each subproblem is one that is easy to be solved. This strategy is referred to as divide-and-conquer.

    This process is also known as stepwise refinement. After each refinement, greater detail is addd to the solution algorithm.
 

      ~~~~ Top-down decomposition ~~~~ 
                                                    (subtask)                                          (smaller subtask)
                  -------->1. Get data --------> 1.1 Get number of hours
                                                            --------> 1.2  Get hourly rate
Payroll -------->2. Calculate --------> 2.1 Calculate regular
 (main task)                     wage                                      wage
                                                                --------> 2.2 Calculate overtime
                                                                                           allowance
                                                                         === 2.2.1 Calculate number of
                                                                                                  overtime hours
                                                                         === 2.2.2 Calculate allowance
                                                                --------> 2.3 Calculate total
                                                                                                          wgae
                  --------> 3. Output wage


 

The diagram above illustrate different levels of decomposition of a problem using a block diagram. We begin by identifying the major tasks to be done to solve the problem and arranging them in the order that they are to be carried out. If these tasks are still complex, we subdivide them into smaller subtasks, resulting in additional levels.
 

Since the decomposition starts st the top level and then works down, we call this method top-down design. The task indentified at each level of subdivision is called a module.