topic badge

12.13 Sorting algorithms

Worksheet
Sorting algorithms
1

Use the insertion sort algorithm to arrange these numbers in ascending order, writing the result of each step of the insertion sort.

8, \quad 3, \quad 2, \quad 1, \quad 5, \quad 4

2

For each of the following data sets:

i

Use the insertion sort algorithm to arrange these numbers in ascending order, writing the result of each step of the insertion sort.

ii

Hence find the median of the data set.

a

72, 26, 63, 48, 31, 55, 17

b

864, 332, 225, 777, 626, 168, 493, 533

3

Consider the following set of data:

5, \, 7, \, 9, \, 4, \, 3, \, 6, \, 4, \, 1, \, 2, \, 3, \, 6, \, 7, \, 8, \, 9, \, 5, \, 2, \, 1, \, 5

a

Sort the numbers into the buckets below.

\text{Bucket}123456789
b

Arrange the data set in ascending order.

c

Hence find the median of the data set.

4

Consider the following set of data:

9415, \quad 95, \quad 9, \quad 690, \quad 189, \quad 5, \quad 3002, \quad 83, \quad 583, \quad 3, \\ 5667, \quad 46, \quad 2, \quad 2669, \quad 74, \quad 492, \quad 419, \quad 13, \quad 6, \quad 6167

a

Sort the numbers into the buckets below based on the number of digits they have.

\text{Bucket}1 \text{ digit}2 \text{ digit}3 \text{ digit}4 \text{ digit}
b

Arrange the values in each bucket in increasing order:

i

1 digit numbers.

ii

2-digit numbers.

iii

3-digit numbers.

iv

4-digit numbers.

c

Arrange the data set in ascending order.

d

Hence find the median of the data set.

5

Consider the following set of data:

81, \quad 31, \quad 12, \quad 94, \quad 65, \quad 28, \quad 47, \quad 54, \quad 76, \\ 93, \quad 71, \quad 11, \quad 35, \quad 27, \quad 85, \quad 42, \quad 66, \quad 56

a

Sort the numbers into the buckets below based on their tens digit.

\text{Bucket}123456789
b

Sort the numbers in each bucket in ascending order from top to bottom.

\text{Bucket}123456789
c

Arrange the data set in ascending order.

d

Hence find the median of the data set.

6

Consider the following set of data:

94, \quad 87, \quad 69, \quad 53, \quad 38

a

Use the bubble sort algorithm to arrange these numbers in ascending order. Write the result of each step of the bubble sort.

b

Hence find the median of the data set.

7

Consider the following set of data:

755, \quad 76, \quad 188, \quad 23, \quad 340, \quad 235, \quad 16, \quad 82

a

Use the merge sort algorithm to arrange these numbers in ascending order. Write the result of each step of the merge sort.

b

Hence find the median of the data set.

8

Consider the follwoing set of data:

78, \quad 12, \quad 6, \quad 63, \quad 24, \quad 49, \quad 9, \quad 5

a

Use the merge sort algorithm to arrange these numbers in ascending order, writing the result of each step of the merge sort.

b

Hence find the median of the data set.

Applications
9

When graphics programmers want to create a frame in their game, they need to make sure the colours of objects in the frame don't blend in to each other. They input the desired distance of each object from the camera, and the computer then sorts the objects in order from the closest to the furthest from the camera.

a

Six objects in a particular frame are the following distances from the camera:

8, \quad 4, \quad 3, \quad 1, \quad 6, \quad 5

Using the insertion sort algorithm, write each step that the computer would produce to put these numbers in ascending order.

b

A graphics programmer coded in the distances of the following objects from the camera:

Object\text{Ocean}\text{Bridge}\text{Knight}\text{Helmet}\text{Boat}\text{Tower}
Distance843165

For this particular frame, which object will appear third closest to the player on the screen?

10

In a game of cards where each player is initially given 6 cards, Oprah is given her cards in the order shown:

To make it easier for her to see her highest valued cards, she uses bubble sort to order the cards so they are in increasing order. Picture cards are of highest value.

a

Following the bubble sort algorithm, on which numbered swap will Oprah need to swap the 2 of clubs with the 5 of spades?

b

State two cards that she will never need to swap.

Sign up to access Worksheet
Get full access to our content with a Mathspace account

What is Mathspace

About Mathspace