T3 Homework 3
T3 Homework 3
Unit 6 Algorithms
1. (a) What would be the state of the following list after each of the first four passes in a
Bubble sort, sorting into ascending sequence?
65, 34, 28, 68, 52, 21
(b) How many passes will be made through the list used in part (a) using the
Bubble sort algorithm in order to sort it?
Merge Sort
1
Homework 3 Sorting algorithms
Unit 6 Algorithms
(b) Describe the process of sorting the following list using the above algorithm:
74, 36, 81, 25, 19, 14, 61, 40
[74,36,81,25] [19,14,61,40]
74 36 81 25 19 14 61 40
36 74 25 81 14 19 40 61
25,36,74,81 14,19,40,61
14,19,25,36,40,61,74,81
You select the first value in the list and the algorithm works through each item in a list till ot
reaches the end. It makes two lists- an unsorted list and a sorted list. It places the chosen
item in the correct place in the list.
2
Homework 3 Sorting algorithms
Unit 6 Algorithms
(b) Show the stages of the sort. The first stage is shown below:
Stage 1: 45, 63, 73, 23, 81, 18
(c) Give one reason why an Insertion sort may be chosen over a bubble sort for
sorting a large number of items.
Bubble sort goes through each pair over and over again
[Total 20 Marks]