- Advanced
- About 13 min
- 5 practice questions
Algorithms and flowcharts
Write algorithms as clear numbered steps, read flowchart symbols and trace a flowchart to find its output.
If something looks wrong, please tell us.
An algorithm is a finite, ordered set of clear steps that solves a problem. Before writing code, programmers plan with algorithms and flowcharts. Exams ask for the properties of an algorithm and for the symbols of a flowchart.
Properties of a good algorithm
- Input: zero or more values given to it.
- Output: at least one result.
- Definiteness: every step is clear and unambiguous.
- Finiteness: it ends after a limited number of steps.
- Effectiveness: every step is simple enough to carry out.
Flowchart symbols
| Symbol | Meaning |
|---|---|
| Oval (terminator) | Start or End |
| Parallelogram | Input or Output |
| Rectangle | Process or calculation |
| Diamond | Decision with Yes and No branches |
| Arrow | Direction of flow |
| Circle | Connector joining parts of a chart |
Worked example 1: write an algorithm
Find the larger of two numbers A and B. Step 1: Start. Step 2: Read A and B. Step 3: If A is greater than B, print A. Step 4: Otherwise, print B. Step 5: Stop. With A = 7 and B = 12, step 3 is false, so the output is 12.
Worked example 2: trace a flowchart
Start. Set S = 0 and N = 1. Decision: is N greater than 4? If No, S = S + N, N = N + 1 and go back to the decision. If Yes, print S. Trace: N = 1, S = 1; N = 2, S = 3; N = 3, S = 6; N = 4, S = 10; N = 5, so the test is Yes and the output is 10 (the sum 1 + 2 + 3 + 4).
Diamond decides, rectangle processes, parallelogram handles input and output.
Key takeaways
- An algorithm is finite, definite and has output.
- Know the five main flowchart symbols.
- Trace with a small table of variables.
Check your understanding
-
1. An algorithm that never ends fails which property?
- Definiteness
- Finiteness
- Effectiveness
- Input
Show answer
Answer: B. Finiteness means the algorithm ends after a limited number of steps.
-
2. Which property says that every step must be clear and unambiguous?
- Finiteness
- Effectiveness
- Output
- Definiteness
Show answer
Answer: D. Definiteness: every step is clear and unambiguous. Effectiveness means each step is simple enough to carry out.
-
3. Flowchart: set S = 0 and N = 1. Decision: is N greater than 3? If No, S = S + N, N = N + 1 and go back to the decision. If Yes, print S. What is printed?
- 10
- 3
- 6
- 4
Show answer
Answer: C. N = 1, S = 1; N = 2, S = 3; N = 3, S = 6; N = 4 makes the test Yes, so 6 (1 + 2 + 3) is printed.
-
4. Which flowchart symbol is the connector that joins parts of a chart?
- Oval
- Diamond
- Circle
- Rectangle
Show answer
Answer: C. A circle is the connector. The oval is the terminator for Start and End.
-
5. Which statement about the input and output of an algorithm is correct?
- It needs at least one input and may give no output
- It takes exactly one input and gives exactly one output
- It takes no input and gives no output
- It takes zero or more inputs and gives at least one output
Show answer
Answer: D. The properties are: input, zero or more values; output, at least one result.
Sign in to keep track of the lessons you finish.