GoalShow that the order of steps in an algorithm can change the result.
New words
algorithm · a set of steps, in order, that tells how to do a taskorder · which step comes first, which comes next and which comes lastwall · a blocked square that a character cannot go through
Explanation
An algorithm is a set of steps in a good order. If the order is wrong, the character may not get where it should go. Look at the map. The cross is a wall. “Down 2, then right 3” walks into the wall. “Right 3, then down 2” reaches the flower. The same steps in a different order can give a different result.
Worked examples
Algorithm B: right 3, then down 2. The cat walks along the top and then down. It reaches the flower.
Algorithm A: down 2, then right 3. After down 1 the cat is next to the wall. Down 2 sends it into the wall, so it cannot get to the flower.
Good order
Bad order
1 write the card
1 put the card in the envelope
2 put it in the envelope
2 post it
3 write the address
3 write the card
4 post it
4 write the address
Order matters for everyday tasks too. Here are the steps for sending a birthday card, first in a good order and then in a bad order.
Class activity
Floor map: make a map on the floor with 5 columns and 4 rows of squares, using chalk, tape or paper. Put a toy flower in one square and a book in another square for a wall. A child is the character. Another child reads out an algorithm, such as “right 2, down 3”. The character moves one square for each number. Does the character reach the flower? Try a different order of the same steps. Find two different algorithms that both reach the flower.
Practice
1
Which algorithm reaches the star: A: right 3, down 2, or B: down 2, right 3?
B. Algorithm A goes right along the top row into the wall in the last square of that row.
2
Put the steps for wrapping a present in a good order. A: add the ribbon. B: put the gift in the box. C: wrap the box in paper. D: close the box.
B, D, C, A. First the gift goes in, then close the box, wrap it, and add the ribbon last.
3
Write the algorithm for the route of the cat.
Right 2, down 2, right 1.
4
In the first map, the algorithm “right 1, down 2, right 2” starts at the cat. Does it reach the flower?
Yes. Right 1, down 2 and right 2 end on the flower and do not touch the wall. There can be more than one good algorithm.