AdvertisementYour brand could be hereYour brand hereOn every Darslab page · students, parents and teachersinfo@darslab.comAsk for pricesPricesinfo@darslab.com
☰ Year plan · Computing

Fewer steps, less time

Week 28 · Unit 12: Be a problem solver · 3 lessons
1

Fewer steps, same job

Computing 5: Unit 12, pp. 159–170
GoalSay what makes an algorithm efficient and compare two algorithms that do the same job.
New words
efficient · doing a job with the fewest steps or in the shortest timealgorithm · a set of steps in order that solves a problemrepeat · a block that runs the blocks inside it again and againcompare · to look at two things and say how they are alike and different
Explanation

Two algorithms can solve the same problem in different ways. The more efficient one takes less time or uses fewer steps. To make an algorithm efficient, first break the problem into small parts. Then put the parts together in a good order. A repeat block is a great helper. When the same steps come again and again, one repeat block can replace many copies. The result is the same, but the program is shorter and easier to change. Efficient does not mean sloppy. The shorter algorithm must still do the whole job correctly.

Long waywhenclickedpen downmove50stepsturn ↻90degreesmove50stepsturn ↻90degreesmove50stepsturn ↻90degreesmove50stepsturn ↻90degreesShort waywhenclickedpen downmove50stepsturn ↻90degreesrepeat4
Worked examples
ProgramBlocks that drawChanges for a bigger square
long way84
short way2 (inside repeat 4)1
Both programs draw the same square with the pen. The long way has 8 move and turn blocks. The short way has 2 blocks inside one repeat block. To draw a bigger square, the short way needs one change, but the long way needs four.
AlgorithmWalks to the shelfWalks to the tables
A: one cup at a time44
B: four cups on a tray11
Efficiency matters in real life too. Four tables in a classroom need a cup each. Algorithm A takes one cup at a time. Algorithm B carries all four cups on a tray. Both put 4 cups on the tables, but B uses fewer walks from the shelf.
AlgorithmStepsTime
X512 minutes
Y79 minutes
Sometimes the number of steps is not the only thing to compare. We can also compare the time. An algorithm with fewer steps that has a long, slow step can still take longer.
Class activity

Move the counters (pairs, 12 counters or buttons, a bowl and a plate). Algorithm A: pick up one counter, put it on the plate, repeat 12 times. Algorithm B: pick up three counters, put them on the plate, repeat 4 times. Count the trips and time each algorithm with a timer. Which is more efficient? What if you could carry 6 counters at a time? Is there a limit to how many you can carry?

Practice
1
Do these two scripts draw the same shape? Which one is more efficient, and why?
Script 1whenclickedpen downmove40stepsturn ↻120degreesmove40stepsturn ↻120degreesmove40stepsturn ↻120degreesScript 2whenclickedpen downmove40stepsturn ↻120degreesrepeat3
2
Algorithm P takes 12 steps. Algorithm Q takes 9 steps. Both do the same job correctly. Which is more efficient by the number of steps? What else could we compare?
3
A bus route takes 14 minutes. A second route to the same place takes 11 minutes. Which one is more efficient by time, and how much quicker is it?
RouteTime
first route14 minutes
second route11 minutes
4
Write a short program with a repeat block that says ‘Hello!’ five times, with a short wait between each one.