Algorithm - Well-defined instructions that perform some tasks and stops in finite time
How to represent algorithms? 1. Use natural languages
too verbose
too "context-sensitive"- relies on experience of reader
2. Use formal programming languages
too low level
requires us to deal with complicated syntax of programming language
3. Pseudo-Code - natural language constructs modeled to look like statements available in many programming languages
Pseudo-Code is simply a numbered list of instructions to perform some task.
Example - Computing Weekly Wages: Gross pay depends on the pay rate and the number of hours worked per week. However, if you work more than 40 hours, you get paid time-and-a-half for all hours worked over 40. Pseudo-code the task of computing gross pay given pay rate and hours worked.
1. get hours worked
2. get pay rate
3. if hours worked ≤ 40 then
3.1 gross pay = pay rate times hours worked
4. else
4.1 gross pay = pay rate times 40 plus 1.5 times pay rate times (hours worked minus 40)
5. display gross pay
6. halt
variables: hours worked, ray rate, gross pay
This example introduces the conditional control structure. On the basis of the true/false question asked in line 3, we execute line 3.1 if the answer is True; otherwise if the answer is False we execute the lines subordinate to line 4 (i.e. line 4.1). In both cases we resume the pseudo-code at line 5.
http://userpages.wittenberg.edu/bshelburne/Comp150/Algorithms.htm