Maths algorithms – flowcharts, pseudocode, Python and trace tables

MathematicsSets, Logic & Graph TheoryAges 11–12

Loading…

Use with my class ✨ Customize with AI Report a problem

Step through 11 maths algorithms shown as a flowchart and as pseudocode or Python while a trace table fills row by row: classifying quadrilaterals and triangles with yes/no questions, testing two triangles for congruence or similarity, Euclid's algorithm, a prime test, bubble sort, a threshold loop on a sequence, a Monte Carlo estimate of π, bisection for a square root, solving a quadratic equation and a fence problem. Students edit numbers, comparisons or the order of tests inside the program, run it again and predict the next row of the trace table.

Lesson: Algorithms, flowcharts and trace tables in mathematics

What it shows

An algorithm is a finite sequence of precise steps. This simulation runs a fixed set of classic maths algorithms one step at a time and shows each in three linked forms: a flowchart with the standard symbols (terminator, input/output, process, decision), a program in pseudocode or Python, and a trace table that records every value. The examples cover classifying shapes with yes/no questions, the SSS, SAS and ASA tests, Euclid's algorithm, trial division, bubble sort, threshold loops, Monte Carlo estimation, bisection, the quadratic formula and an optimisation problem.

How to use

Choose an Algorithm, type the inputs and click Step: the box just run turns yellow in the flowchart and in the program, and a row is added to the trace table. Click Run to keep going or Run to end to see the result. Edit the blue boxes in the program, or click ↑ to reorder the tests, then run again. Tick Predict next row to type each new value or answer Yes/No before the step runs.

Parameters you can change

  • Algorithm Classify quadrilaterals (yes/no questions), Classify triangles by sides and angles, Congruent or similar triangles, Euclid's algorithm for the HCF, Prime test, Bubble sort of numbers, Threshold loop on a sequence, Monte Carlo estimate of π, Guess, check, refine: bisection for √N, Solving a quadratic equation, Fence: the largest rectangle
  • Program language Pseudocode, Python
  • Predict the next row of the trace table
  • Run speed 1–20 steps/s
  • Inputs separated by ; (empty = the algorithm's default data)

Questions to explore

  1. How many times does the loop in Euclid's algorithm run for a = 252 and b = 105?
  2. Why does the prime test call 25 prime when d · d ≤ n is changed to d · d < n?
  3. What happens to a square if the test p = 2 is moved to the top of the chain, and why?