Sorting is the process of arranging items systematically, into different groups or order. The main purpose of sorting information is to make it easier to deal with the items or search for information.
Examples of why humans might like to sort items include:
Sorting cards in your hand to make it easier to find the right card to play
Sorting coins and notes in a bank to make it easier to determine the total value of money
Sorting numbers to make it easier to determine the highest, lowest or middle number
Computer programmes also need to sort data so that they can locate information and then perform operations on this information.
For our purposes we will be humans pretending to act like computers.
It can be easy to sort items when there are only a small number of items, but it becomes much more difficult when there are many items to sort. We can use algorithms to make the sorting process more efficient. There are many sorting algorithms, we will look at the following 5 algorithms:
Selection Sort
Insertion Sort
Bubble Sort
Bucket Sort
Merge Sort
Selection Sort involves systematically finding the numbers in order and swapping them into position until the numbers are in order.
The following steps and example show how to sort a list into ascending order (smallest to biggest) using the selection sort algorithm.
Insertion Sort involves moving from left to right and determining the correct position for each number and inserting into their correct position.
The following example shows how to sort a list into ascending order (smallest to biggest) using the insertion sort algorithm.
We want to use the insertion sort algorithm to manually sort the following set of data and then find the median. 72, \, 26, \, 63, \, 48, \, 31, \, 55, \, 17
Use the insertion sort algorithm to arrange these numbers in ascending order.
Find the median of the data set.
Selection Sort involves systematically finding the numbers in order and swapping them into position until the numbers are in order.
Insertion Sort involves moving from left to right and determining the correct position for each number and inserting into their correct position.
Bubble sort involves comparing pairs of adjacent elements of the sequence, if they are in the wrong order swap them and do this until there are no swaps to do.
The following steps and example show how to sort a list into ascending order (smallest to biggest) using the bubble sort algorithm:
The Bucket sort algorithm involves placing data in buckets or bins. These bins may represent single numbers or they may represent ranges of numbers that then have to be sorted using another sorting algorithm ( eg. insertion).
The example shows how to sort a list into ascending order (smallest to biggest) using the bucket sort algorithm.
We want to use the bucket sort algorithm to manually sort the following set of data and then find the median.81, \, 31, \, 12, \, 94, \, 65, \, 28, \, 47, \, 54, \, 76, \, 93, \, 71, \, 11, \, 35, \, 27, \, 85, \, 42, \, 66, \, 56
Sort the numbers into the buckets below based on their tens digit.
Each number belonging to that column should be entered in the order that they appear in the list.
\text{Bucket} | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
---|---|---|---|---|---|---|---|---|---|
⬚ | ⬚ | ⬚ | ⬚ | ⬚ | ⬚ | ⬚ | ⬚ | ⬚ | |
⬚ | ⬚ | ⬚ | ⬚ | ⬚ | ⬚ | ⬚ | ⬚ | ⬚ |
Sort the numbers in each bucket in ascending order from top to bottom.
Arrange the data set in ascending order.
Find the median of the data set.
Bubble sort involves comparing pairs of adjacent elements of the sequence, if they are in the wrong order swap them and do this until there are no swaps to do.
Bucket sort involves placing data in buckets or bins. These bins may represent single numbers or they may represent ranges of numbers that then have to be sorted using another sorting algorithm.
Merge sort divides the list of numbers into smaller and smaller groups, orders them then combines them back together.
We want to use the merge sort algorithm to manually sort the following set of data and then find the median.78,\,12,\,6,\,63,\,24,\,49,\,9,\,5
Use the merge sort algorithm to arrange these numbers in ascending order.
Hence find the median of the data set.
Merge sort divides the list of numbers into smaller and smaller groups, orders them then combines them back together.