Name: Class:
Task 1 Bubble sort
Your teacher will give you a set of name cards.
Place the cards in the sequence of numbers 1, 2, 3… 10
Perform a manual Bubble Sort to get the cards in alphabetical order.
1. What are the last two names after the first pass?
Boys set of cards:
Girls set of cards:
2. What are the first two names after the second pass?
Boys set of cards:
Girls set of cards:
3. What are the third and fourth names after the third pass?
Boys set of cards:
Girls set of cards:
4. What are the seventh and eighth names after the fourth pass?
Boys set of cards:
Girls set of cards:
5. What are the fourth and fifth names after the fifth pass?
Boys set of cards:
Girls set of cards:
1
6. What are the first two names after the sixth pass?
Boys set of cards:
Girls set of cards:
7. Which names are out of sequence after the seventh pass?
Boys set of cards:
Girls set of cards:
8. Are any names out of sequence after the eighth pass?
Boys set of cards:
Girls set of cards:
9. How many passes were needed to sort the cards?
Boys set of cards:
Girls set of cards:
Task 2: Insertion sort
Lay out the name cards that you used in Task 1 in the sequence of numbers 1, 2, 3… 10
1. On the first pass, you are comparing the second card with the first.
What are the first two names after the first pass?
Boys set of cards:
Girls set of cards:
2. What are the second and third names after the second pass?
Boys set of cards:
Girls set of cards:
2
3. What are the third and fourth names after the third pass?
Boys set of cards:
Girls set of cards:
4. What are the first five names after the fourth pass?
Boys set of cards:
Girls set of cards:
5. How many passes are needed to sort all 10 names?
Boys set of cards:
Girls set of cards:
Task 3: Merge sort
Lay out the first 8 name cards that you used in Task 1 in the sequence of numbers 1, 2, 3… 8
1. Split the cards into two sublists.
What names are in first sublist?
Boys set of cards:
Girls set of cards:
2. Split the lists into two further sublists each.
What names are in the third sublist?
Boys set of cards:
Girls set of cards:
3
3. Split the pairs into single items.
Now merge each pair separately
Are they all in sequence?
Boys set of cards:
Girls set of cards:
4. Now merge the four pairs into two groups of four. What are the names in the first sorted
group?
Boys set of cards:
Girls set of cards:
5. Now merge the two groups together. What is the third card in the list?
Boys set of cards:
Girls set of cards:
Task 4: Comparing sorts
Go to the website http://www.sorting-algorithms.com/ to compare the Insertion, Bubble and
Merge sort for 50 items. Which sort is fastest?
Which is slowest?
4
Task 5: Algorithms
You have studied three algorithms for sorting.
Look at the following algorithm written in pseudocode for one type of sorting algorithm.
1 names = ["Toby", "Abdul","Gale","Ruby","Amy","Boris"]
2 numItems = names.length - 1
3 while numItems > 1:
4 for item=0 to numItems:
5 if names[item] > names[item+1]:
6 temp = names[item]
7 names[item] = names[item+1]
8 names[item+1] = temp
9 endif
10 endfor
11 numItems = numItems-1
12 endwhile
13 for i=0 to numItems
14 print(names[i])
15 endfor
1. There is a for loop at the end of the algorithm (lines 13-15) which contains the pseudocode:
print(names[i])
What do you think this does?
2. At the start of the program, the array called names is initialised with six names.
What will the value be that is stored in numItems?
5
3. Look at lines 5 to 9 in the code and explain what they are doing.
4. State the type of sorting algorithm that has been given.