Gradient

Courses

∇\nabla∇The maths behind AI0/72
π\piπMaths0/84
⋆\star⋆AI for everyone0/10
Γ\GammaΓGame theory0/49
py\texttt{py}pyPython for AI0/15
y^\hat{y}y^​Build your own AI0/15
All courses

Tuition

My tuitionOlympiad trackCompetitions

Practice

ProjectsAsk a questionTrain on a GPUExplorationsMaths StoriesUnsolved problemsPlaygroundScience labsMock testsOlympiad

Reference

GlossaryBlogDiscoveries
Competitions › SOF ICSO › unit 14 of 16

Algorithms and flowcharts

SOF ICSO · AI, Robotics and IT · about 6 minutes

An algorithm is a clear, finite list of steps to solve a problem. A flowchart draws it with standard shapes.

Questions ask you to trace a flowchart, find its output or spot a missing step.

In this lesson

  1. Shapes
  2. Tracing
  3. Worked examples
  4. Where marks are lost
  5. Check yourself

1Shapes

Each shape has one job, so anyone can read a flowchart. Arrows show the order. A decision diamond always has two exits, labelled yes and no.

2Tracing

Make a column for each variable and one row per step. Update the values exactly as the chart says and stop when you reach End.

Worked examples

  1. Example 1Start with s = 0, i = 1. Repeat: s = s + i, i = i + 2, until i > 7. Output s.

    1. Add 1, 3, 5, 7.

    Answer: 16

See it move

Where marks are lost

  • Running a loop one time too many.
  • Using a rectangle for a decision.

Exam tips

  • Oval: start/end. Parallelogram: input/output. Rectangle: process. Diamond: decision.
  • A loop goes back to an earlier step until a condition changes.
  • Trace with a table of variable values.

Practice questions

  1. Which flowchart symbol shows a decision?

  2. An algorithm must be…

  3. A flowchart sets n = 1 and doubles n until n > 20. The final n is…

More worked examples

Try each one first, then open the working.

  1. Trace the flowchart. What number is printed?

    Starts = 0, n = 14n > 0?yess = s + nn = n − 3noprint sEnd
    Show the working

    Start: Write down s and n after every pass round the loop.

    s takes the values 14 + 11 + 8 + 5 + 2 = 40.

    Answer: 40

  2. Fill the trace table. What value replaces “?”?

    total = 0for i in range(0, 4):total = total + i * 4itotal00142123?
    Show the working

    Start: Each row adds i × k to the total from the row above.

    total after i = 3: 0 + 4 + 8 + 12 = 24.

    Answer: 24

  3. How many times does this run? for i in range(4, 9, 3):

    Show the working

    Start: List the values of i.

    range stops before the end value.

    Answer: 2

  4. Trace the flowchart. What number is printed?

    Starts = 0, n = 14n > 0?yess = s + nn = n − 2noprint sEnd
    Show the working

    Start: Write down s and n after every pass round the loop.

    s takes the values 14 + 12 + 10 + 8 + 6 + 4 + 2 = 56.

    Answer: 56

Practise more

New questions every time, at exam level

Trace the flowchart. What number is printed?

Startp = 1, k = 0k < 4?yesp = p × 2k = k + 1noprint pEnd

Learn it properly

Full chapters with animations, each with an “Explained simply” version.

  • Algorithms and flowchartsClass 7

Sit a timed SOF ICSO mock test

Cyber safety and securityNext: AI and robotics basics