## Starter

Have a go at this sorting game. How quickly can you sort all the letters just by clicking on letters to swap?

## Intro

### 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.

Imagine:

- 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

## Insertion Sort

### Insertion 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.

Can’t access YouTube? Click here for the Google Drive Version

## Bubble Sort

### Bubble Sort

With bubble sort, you go through the list, comparing pairs of items and swapping them if necessary. This algorithm is very slow because you have to keep traversing the list many times.

Can’t access YouTube? Click here for the Google Drive Version

## Selection Sort

### Selection Sort

With selection sort, you look through the list, find the smallest item, and then move that item to a new list. You keep going until the original list is empty. This method is very slow as you have keep traversing the list to find the smallest item.

Can’t access YouTube? Click here for the Google Drive Version

## Activity 1

### 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 below

Scratch Practise## Activity 2

### Activity 2 – Complete your learning log

Fill out your learning log for today’s lesson. (see lesson one for information)