← Angles and shapes

Algorithms for classifying shapes

An algorithm is a clear set of steps and decisions. A classification algorithm asks yes/no questions about a shape's sides and angles, in an order that gives each shape its own name, and you test it on one shape of every class.

A sorting machine at a factory has to name every shape that rolls past, with no one to help. What questions would you build into it, and in what order?

An algorithm is a precise set of steps, including decisions, that always gives the right result. A classification algorithm sorts shapes into classes by asking yes/no questions about their attributes (sides, angles, parallel sides). It can be drawn as a flowchart or a decision tree, or written as numbered steps (pseudocode).

Two things make one work: every shape reaches exactly one answer, and the questions are in the right order.

PredictRead the problem and decide what you think before you try anything. A wrong guess is fine: it shows you what to look for.

An algorithm with one question

Would you be happy with that answer from a sorting machine?

An algorithm asks only: 'Are two sides equal? Yes: isosceles. No: scalene.' A triangle has sides 4, 4 and 4. What does it say?

TryTry it on the board and compare the result with your prediction.

Follow the algorithm

Read each shape's description, answer the question, and press the button to go on.

Try it yourselfYour edits are saved in this browser.

Follow this two-question algorithm for each triangle in turn. How does it name the 4, 4, 4 triangle? Compare with your prediction.

Use the board. This ticks when you get there.

InvestigateWork out why it happens, one step at a time.

What goes wrong

Which class does the algorithm confuse with another?

Read Pia's working. What name did the rectangle get?

How can you fix the one-question triangle algorithm?

Pia tests her algorithm on a rectangle. Click the line where she wrongly decides it works.

How should you test a classification algorithm?

ModifyChange the problem on purpose and see what happens.

Design and test

Measure first. Which question is the most specific?

Try it yourselfYour edits are saved in this browser.

Put the steps of a triangle algorithm in order.

Pieces (click to add)
    Your program

      Run the fixed algorithm on all three triangles. Does every one get the right name?

      Use the board. This ticks when you get there.

      Run the quadrilateral algorithm on all five shapes.

      Use the board. This ticks when you get there.

      A kite (two pairs of equal neighbouring sides, no parallel sides) is put through the quadrilateral algorithm. What happens?

      PractiseA few on your own, to check you have it.

      Tracing algorithms

      Try it yourselfYour edits are saved in this browser.

      In the fixed triangle algorithm, how many questions does a scalene triangle need before it is named?

      A rhombus (four equal sides, angles 60° and 120°) goes through the quadrilateral algorithm. Which answers does it give, in order?

      The quadrilateral algorithm asks at most how many questions before naming any of its five shapes?

      Review: a triangle has angles 90°, 45° and 45°. How many of its sides are equal?

      MakeMake your own problem using what you have learned. Expect a few tries; that is normal.

      Design a classifier

      Now write an algorithm that sorts triangles by their angles into acute, right-angled and obtuse. Test it on one triangle of each class, and say how it works to a partner.

      Try it yourselfYour edits are saved in this browser.
      Need a hint?

      Answer each question using the shape's description.

      Another hint

      If the key names the wrong shape, find the question you answered wrongly.

      Run the quadrilateral algorithm on all five shapes again, and say each answer aloud as you go.

      Use the board. This ticks when you get there.

      For teachers

      Students follow, fix and test algorithms that classify triangles and quadrilaterals, and describe how each works (AC9M7SP04, nodes 1 and 2). About 40 minutes.

      Open the teacher guide: answers, solutions, slides and a worksheet.

      Students will be able to

      Before class

      Do the Run board yourself first. Students need the triangle and quadrilateral classes (Classifying shapes lessons).

      The one idea: each shape must reach its own name, so the most specific question comes first. A short algorithm can be wrong; testing on one shape of every class finds it (Pia's mistake).

      The board follows the key one question at a time; it is the same tool students use for living things in science. Students design on paper: the Make task asks for an algorithm for triangles by angles, drawn as a flowchart or written as numbered steps.

      Judging two algorithms for efficiency (fewest questions) and for edge cases (the kite) are wider ideas.

      This links to Code: an algorithm written in steps is a program with if and else.

      Running the lesson

      1. Predict: ask what the machine should say for the equilateral triangle.
      2. Run: ask which triangle the algorithm gets wrong, and why.
      3. Investigate: ask what test shapes Pia should have used.
      4. Modify: ask students to describe the quad algorithm in words.
      5. Make: ask a partner to run the algorithm on a shape the author hasn't tried.

      The hard part (on purpose)

      Ordering the questions. Ask students to say which shape each question separates before they put it in a position.

      When students get stuck

      Stretch and support

      Stretch: Compare two correct algorithms for the same job: which asks fewer questions on average? Then write the triangle algorithm in Python with `if` and `else`.

      Support: Give students the questions on cards and ask them to lay out the order before they use the board.

      Where it leads

      This completes AC9M7SP04.

      Where it leads: algorithms in code (the Code pathways), flowcharts for other decisions, and decision trees in Probability.

      What each step is for

      Now you can
      Practise this skillNew questions, new numbers each timeGet 3 right in a row to mark it practised.Next lesson16. Congruent trianglesCongruent triangles are the same shape and size. You don't need all six parts to check: some sets of three parts fix the triangle (the congruence tests: SSS, SAS, ASA or AAS, RHS), and one set of three can fit two different triangles.