- Practice
- About 13 min
- 5 practice questions
Algorithms and flowcharts
Write simple algorithms, identify flowchart symbols and trace a flowchart to find its output.
If something looks wrong, please tell us.
An algorithm is a finite, step-by-step set of instructions to solve a problem. A flowchart is a diagram of an algorithm using standard symbols. Exams ask you to name the symbols and to trace what a given flowchart produces.
Qualities of a good algorithm
- Clear and unambiguous steps.
- Finite: it must end.
- Has defined input and output.
- Every step is simple enough to carry out.
Flowchart symbols
| Symbol | Meaning |
|---|---|
| Oval | Start or end (terminator) |
| Parallelogram | Input or output |
| Rectangle | Process or calculation |
| Diamond | Decision with yes/no branches |
| Arrow | Direction of flow |
Worked examples
Example 1. Algorithm to find the larger of two numbers A and B: Step 1 start. Step 2 read A and B. Step 3 if A > B, print A; otherwise print B. Step 4 stop. For A = 7 and B = 12, the output is 12.
Example 2. Trace this algorithm: set S = 0; set N = 1; while N <= 4, add N to S and then add 1 to N; print S. Step by step: S = 1, then 3, then 6, then 10. Output is 10 (that is, 1 + 2 + 3 + 4).
Oval starts and ends, parallelogram is input or output, rectangle processes, diamond decides.
Key takeaways: know the five symbols and trace algorithms with a small table of variable values.
Check your understanding
-
1. Which flowchart symbol marks Start or End?
- Diamond
- Rectangle
- Parallelogram
- Oval
Show answer
Answer: D. The oval (terminator) marks the start and end of a flowchart.
-
2. Algorithm: read A and B; if A > B, print A; otherwise print B. What is printed for A = 15 and B = 9?
- 9
- 24
- 15
- 6
Show answer
Answer: C. 15 > 9 is true, so A, which is 15, is printed.
-
3. Trace: S = 0; N = 1; while N <= 3, add N to S and then add 1 to N; print S. What is printed?
- 10
- 6
- 3
- 4
Show answer
Answer: B. S becomes 1, then 3, then 6. N becomes 4, the condition 4 <= 3 fails, and 6 (1 + 2 + 3) is printed.
-
4. Which flowchart symbol is used for a process or calculation?
- Oval
- Diamond
- Parallelogram
- Rectangle
Show answer
Answer: D. A rectangle holds a process or calculation, such as S = S + N.
-
5. Which of these is NOT a quality of a good algorithm?
- It must end after a limited number of steps
- It has defined input and output
- Every step is simple enough to carry out
- Steps that can be understood in more than one way
Show answer
Answer: D. A good algorithm has clear and unambiguous steps. A step that can be read two ways breaks that rule.
Sign in to keep track of the lessons you finish.