- Foundation
- About 12 min
- 5 practice questions
Algorithms and flowcharts
Define an algorithm, write one in plain steps and read basic flowchart symbols.
If something looks wrong, please tell us.
Before writing any program, a programmer plans the steps. That plan is an algorithm, and a picture of it is a flowchart.
Algorithm
An algorithm is a finite, step-by-step set of instructions to solve a problem. A good algorithm is clear, has a definite start and end, takes input (possibly), produces output and is finite, meaning it must stop.
Algorithm to find the sum of two numbers: 1. Start. 2. Read A and B. 3. Add: Sum = A + B. 4. Print Sum. 5. Stop.
Flowchart symbols
| Symbol | Name | Used for |
|---|---|---|
| Oval | Terminator | Start and Stop |
| Parallelogram | Input / Output | Reading and printing data |
| Rectangle | Process | Calculations and assignments |
| Diamond | Decision | Yes/No question with two exits |
| Arrow | Flow line | Direction of flow |
| Circle | Connector | Joining parts of a chart |
Pseudocode
Pseudocode is a plain-language outline of a program that is not tied to any language. It is easy to read and convert to real code.
Worked examples
Example 1. Algorithm for the area of a rectangle. Start; read length L and breadth B; Area = L x B; print Area; stop. For L = 8 and B = 5, Area = 40.
Example 2. Which flowchart symbol holds the question 'Is the number greater than 10?' The diamond (decision).
Example 3. Average of three numbers 4, 8 and 12. Sum = 24; Average = 24 / 3 = 8.
Algorithm = steps. Flowchart = picture of the steps. Pseudocode = steps in plain words.
Key takeaways
- Plan with an algorithm before coding.
- Know the flowchart symbols.
- Pseudocode is language-free.
Check your understanding
-
1. Which flowchart symbol holds a yes/no question such as 'Is the number greater than 10?'
- Oval
- Diamond
- Rectangle
- Parallelogram
Show answer
Answer: B. A decision is drawn as a diamond with two exits, Yes and No.
-
2. Which flowchart symbol is used for reading and printing data?
- Diamond
- Parallelogram
- Oval
- Circle
Show answer
Answer: B. Input and output are shown with a parallelogram.
-
3. An algorithm reads length L and breadth B and prints Area = L x B. What does it print for L = 9 and B = 6?
- 54
- 15
- 30
- 96
Show answer
Answer: A. Area = 9 x 6 = 54. (15 is L + B and 30 is 2 x (L + B), the perimeter.)
-
4. What is the average of 6, 9 and 15?
- 30
- 15
- 10
- 9
Show answer
Answer: C. Sum = 6 + 9 + 15 = 30. Average = 30 / 3 = 10.
-
5. Pseudocode is
- A program written in 0s and 1s
- A flowchart symbol for decisions
- A plain-language outline of a program that is not tied to any language
- A kind of compiler
Show answer
Answer: C. Pseudocode describes the steps in plain words, independent of any language, so it is easy to read and convert to real code.
Sign in to keep track of the lessons you finish.