• 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

Standard symbols
SymbolMeaning
OvalStart or end (terminator)
ParallelogramInput or output
RectangleProcess or calculation
DiamondDecision with yes/no branches
ArrowDirection 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.

— Memory line

Key takeaways: know the five symbols and trace algorithms with a small table of variable values.

Check your understanding

  1. 1. Which flowchart symbol marks Start or End?

    1. Diamond
    2. Rectangle
    3. Parallelogram
    4. Oval
    Show answer

    Answer: D. The oval (terminator) marks the start and end of a flowchart.

  2. 2. Algorithm: read A and B; if A > B, print A; otherwise print B. What is printed for A = 15 and B = 9?

    1. 9
    2. 24
    3. 15
    4. 6
    Show answer

    Answer: C. 15 > 9 is true, so A, which is 15, is printed.

  3. 3. Trace: S = 0; N = 1; while N <= 3, add N to S and then add 1 to N; print S. What is printed?

    1. 10
    2. 6
    3. 3
    4. 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. 4. Which flowchart symbol is used for a process or calculation?

    1. Oval
    2. Diamond
    3. Parallelogram
    4. Rectangle
    Show answer

    Answer: D. A rectangle holds a process or calculation, such as S = S + N.

  5. 5. Which of these is NOT a quality of a good algorithm?

    1. It must end after a limited number of steps
    2. It has defined input and output
    3. Every step is simple enough to carry out
    4. 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.

Next lesson → Variables, data types and operators

Privacy · Terms · Refunds · Delivery