9_1_6

WHAT: Compare the efficiency of algorithms and understand that there is more than one way to solve a problem.

HOW:

(image from Wikimedia commons)

Activity 1

You started to learn about this in outcome 7_2_8. You might want to re-visit this page first before moving on.

Activity 2

There is more than one way to solve a problem. You have just seen this in the previous outcome. There are two main types of searches: binary and linear. They both solve the problem but one is more efficient than the other.

Take a look at the different sorting algorithms from activity 5 in outcome 7_2_8. Decide which algorithm is more efficient.

Write down your decision and explain your reasons why.

Activity 3

What does efficiency mean? Efficiency in algorithms is completing a task in the least amount of steps using minimal resources.

The two scratch algorithms shown complete the same task. They both move the sprite in the shape of a square.

The first algorithm shows a loop being used to repeat the instructions 4 times. The second algorithm shows the same two instructions being written 4 times.

Which one do you think is more efficient?

Why do you think it is more efficient?

Does your chosen algorithm meet the criteria in the definition above?

Activity 4

The first algorithm could be seen as the most efficient. This is why:

  • It is faster to write
  • It is faster to update
  • It is easier to spot errors

A common misconception is to say that it uses less resources to run. This isn't true because the same number of lines of code will run for both algorithms.

CHECK:

EMBED:

Find a programming challenge that you have solved in the past.

See if it is efficient.

Re-write the solution by trying to make it more efficient.

CLASSROOM IDEAS:

A good demonstration for efficiency is to ask for a volunteer to come up to the front to sort a pack of cards. Make a really big deal about you being extremely fast at sorting cards and that you have an amazing method. The other student should have a minute or so to think of an efficient way to sort the pack.

Then do a countdown 3,2,1 and start sorting your packs.

Instead of sorting your pack. Throw it on the floor really quickly. Try and pick all the cards back up again as quick as you can and check if they are now in the correct order.

The demonstrates the point that efficiency isn't necessarily "faster". We are talking about clever algorithms that solve the problem in the least amount of steps.