9_2_1

WHAT: Compare and contrast bubble and merge sort algorithms.

HOW:

Activity 1

In outcome 7_2_8 you will have taken a look at common key algorithms that are used in Computer Science. You may wish to revisit this section first.

The two YouTube videos that relate to this outcome can be viewed below:

Activity 2

Bubble and Merge sort algorithms solve the same problem in two different ways. You need to be able to compare and contrast them.

What does Compare mean?

Compare means - show the similarities.

What does Contrast mean?

Contrast means - show the differences.

Compare and Contrast’ questions are very common in exams – they want you to say how something is similar and how it may be different too.

Complete some research and re-watch the YouTube videos. Think about the similarities and differences of the two algorithms as you research.

Activity 3

Download, print and complete this worksheet.

CHECK:

EMBED:

Here is some code for a Bubble Sort Algorithm:

def bubbleSort(numbers): #creates a sub-routine for any bubblesort

  for aPass in range(len(numbers)-1,0,- 1):

    print (numbers)

    for x in range(aPass):

      if numbers[x]>numbers[x+1]:

        y = numbers[x]

        numbers[x] = numbers[x+1]

        numbers[x+1] = y      

numbers = [54,26,93,17,77,31,44,55,20]

bubbleSort(numbers)

print(numbers)
  1. Copy and paste it into Python and try to figure out how it works.
  2. Explain each line of code using the #hashtag.
  3. Put your own numbers into the "numbers" array and see if it can solve the sort any faster.

CLASSROOM IDEAS:

In 7_2_8 you might have already used some of the classroom activities below:

CS UNPLUGGED

It might be worth re-visiting them at this point.