• 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

Standard symbols
SymbolMeaning
Oval (terminator)Start or End
ParallelogramInput or Output
RectangleProcess or calculation
DiamondDecision with Yes and No branches
ArrowDirection of flow
CircleConnector 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.

— Memory line

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. 1. An algorithm that never ends fails which property?

    1. Definiteness
    2. Finiteness
    3. Effectiveness
    4. Input
    Show answer

    Answer: B. Finiteness means the algorithm ends after a limited number of steps.

  2. 2. Which property says that every step must be clear and unambiguous?

    1. Finiteness
    2. Effectiveness
    3. Output
    4. Definiteness
    Show answer

    Answer: D. Definiteness: every step is clear and unambiguous. Effectiveness means each step is simple enough to carry out.

  3. 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?

    1. 10
    2. 3
    3. 6
    4. 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. 4. Which flowchart symbol is the connector that joins parts of a chart?

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

    Answer: C. A circle is the connector. The oval is the terminator for Start and End.

  5. 5. Which statement about the input and output of an algorithm is correct?

    1. It needs at least one input and may give no output
    2. It takes exactly one input and gives exactly one output
    3. It takes no input and gives no output
    4. 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.

Next lesson → Variables, data types and operators

Privacy · Terms · Refunds · Delivery