Have a go at this sorting game. How quickly can you sort all the letters just by clicking on letters to swap?
Sorting algorithms – Why do we need them?
One of the most important jobs a computer performs for us is sorting of data. Without sorted data our computer systems would be much harder to use.
- trying to read through all your emails if they were in a random date order.
- finding a friend’s telephone number if all you contacts were in a random order.
- loading an app from your apps list if they were all jumbled up.
There are many different ordering systems we can use, common ones include:
- alphabetical order
- numerical order
- date order
- size order
Different sorting algorithms
There are many different algorithms(methods) for sorting lists of things. In the last task some people will have sorted the letters the fastest (most time efficient) or with the least number of swap (most effort efficient). Have a chat with the person next to about how they sorted out the list. What technique did they use? Whose algorithm was the most time / effort efficient?
In computer science we have many different sorting techniques, some are most efficient than others, some are simpler than others. Today we will be looking at:
- Insertion Sort
- Bubble Sort
- Selection Sort
With the insertion sort algorithm, you go through each item in the list in turn and move to its correct position in the list. The algorithm is slow but simple.
Insertion Sort Tutorial
AS & A Level – You are required to know how it works and be able to write Code / Pseudocode for the algorithm
The bubble sort algorithm works by sorting through the array in pairs. It starts at the left of the array and inspects the first two items. If the items are in the wrong order they are swapped around. The algorithm then carries on with the next pair along and so forth. When it reaches the end of the array it goes back to the beginning of the array and starts again. If it completes a full pass of the array without swapping any items it knows that the array is sorted.
Bubble Sort Python Tutorial
Bubble Sort Demonstration
Activity 1 – People Sorter
Replicate the class activity for each sorting algorithm (this can be done after introducing each sorting algorithm.
Best splitting the class in to groups of 15 or less (otherwise the sorting will take a rather long time!
Alternative Activity – Have a go at sorting letters using the scratch game belowScratch Practise