Algorithms and flowcharts
An algorithm is a finite list of clear steps that solves a problem, like a recipe. Each step must be exact enough that anyone, or a machine, can follow it without guessing, and the algorithm must finish. A flowchart draws the algorithm. The rounded shape marks the start and the end, a slanted box (a parallelogram) is for input and output, a rectangle is a step of work, a diamond is a decision with two exits (yes and no), and arrows show the order. An activity diagram is the same idea drawn for a process. Every algorithm is built from three structures. Sequence: do the steps one after another. Branching: choose a path by a condition, such as “is n even?”. Loop: repeat steps while a condition holds. The first flowchart reads a number n and shows whether it is even (its remainder after dividing by 2 is 0) or odd. The second flowchart repeats: it adds 1, 2 and 3 to a total. Computers cannot guess, so the steps must be written in a programming language; machine language is the 0s and 1s that the processor runs directly, and a programming language such as Python is written for people and translated for the machine.
| Pass | i at the start | total after | i after |
|---|---|---|---|
| 1 | 1 | 1 | 2 |
| 2 | 2 | 3 | 3 |
| 3 | 3 | 6 | 4 |
Write an algorithm in plain steps for making tea or for finding the larger of two numbers. Mark which part is a sequence, which part is a branching and whether there is a loop. Then draw its flowchart on paper with the four kinds of shapes.