Year 8 › Algorithms: search and sort › Lesson 3 of 5
Year 8 · Summer 1 · Algorithms: search and sort Insertion sort and merge sort, unplugged
Topic 12 Searching and sorting
KS3 Computing · Searching finds an item. Sorting puts items in order. Some algorithms are hugely faster than others on big lists, and the difference grows as the list grows.
Computational Thinking Cambridge Lower Secondary Computing 0860
You will learn to Describe insertion sort: take the next item and slide it into place in the sorted part. Describe merge sort: split the list into single items, then merge them back in order. Merge two sorted lists by comparing only their front items. Compare how insertion sort and merge sort felt, and explain which was faster.
Success criteria I can sort a hand of playing cards with insertion sort and explain each move. I can merge [1, 3, 6, 8] and [2, 4, 5, 7] into one sorted list. I can show the list after each step of insertion sort or merge sort.
Bubble sort Swap neighbours until a whole pass makes no swaps.
Insertion sort Slide each item into its place in the sorted part.
Merge sort Split into single items, then merge back in order.
Linear search Check every item in turn.
Binary search Search a sorted list by halving it each step.
Bubble sort Bubble sort : compare neighbours , swap if they're in the wrong order. One trip along is a pass . Stop when a pass makes no swaps.
e.g. Example[5, 1, 4, 2, 8] → pass 1 → [1, 4, 2, 5, 8] → pass 2 → [1, 2, 4, 5, 8] → pass 3: no swaps, done.
! Watch outEasy to code, but very slow on big lists.
Insertion sort Insertion sort : like sorting playing cards. Take the next card and slide it into the right place among the sorted ones.
e.g. Example[5 | 1, 4, 2, 8] → [1, 5 | 4, 2, 8] → [1, 4, 5 | 2, 8] → [1, 2, 4, 5 | 8] → [1, 2, 4, 5, 8].
Merge sort Merge sort : split the list in half again and again until every piece has 1 item. Then merge pieces back together in order.
Split: [6, 3, 8, 1] [5, 2, 7, 4] Split: [6, 3] [8, 1] [5, 2] [7, 4] Split into singles. Merge: [3, 6] [1, 8] [2, 5] [4, 7] Merge: [1, 3, 6, 8] [2, 4, 5, 7] Merge: [1, 2, 3, 4, 5, 6, 7, 8] ★ RememberTo merge, only compare the front item of each list and take the smaller.
Mark this lesson as done Saved on this device.
← Previous lesson Bubble sort, step by step Next lesson → Comparing efficiency by counting comparisons