Types of algorithms and ways to present them
An algorithm can be presented in five ways. In words: each instruction is a short command sentence. With formulas: the actions are given as mathematical formulas (handy for physics and chemistry problems). As a table: like a timetable or a table of values for y = x² – 3. In graphic form: a diagram, drawing, graph and above all a flowchart. As a program: the algorithm is written in a programming language. In a flowchart an oval stands for the start and end, a parallelogram for input and output, a rectangle for calculation and assignment, a rhombus (diamond) for a condition (with “yes” and “no” branches), a hexagon for a loop parameter, and a rectangle with side lines for a subprogram; the blocks are joined by lines with arrows. Because a flowchart is easy to see, it is widely used when preparing to program.
| Block | Meaning |
|---|---|
| oval | start and end |
| parallelogram | input and output |
| rectangle | calculation and assignment |
| rhombus | condition (yes / no) |
| hexagon | loop parameter |
| rectangle with side lines | subprogram |
The class monitor drew the steps for watering the classroom plants as a flowchart: start, check the soil, ask “is it dry?”, if yes give a little water, if no do nothing, finish. A monitor from another group followed the chart without asking any questions.
Programmers, systems analysts and manual writers draw a process as a flowchart to make it clear to everyone.
Draw an everyday task, such as choosing a book from a list, as a flowchart. Use a diamond for the decision; paper and pencil are enough.
| x | –2 | –1 | 0 | 1 | 2 |
|---|---|---|---|---|---|
| y | 1 | –2 | –3 | –2 | 1 |
“One algorithm – five forms”: a group prepares the algorithm “enter the room and switch on the light” as words, a flowchart and a table; the others point out the differences.