What happens in a bubble sort?
Example - rearrange the below data set so its in order from smallest to largest: 75, 10, 26, 97, 68
FIRST PASS:
- Swap 75 and 10 (10, 75, 26, 97, 68)
- Swap 75 and 26 (10, 26, 75, 97, 68)
- Don’t swap 75 and 97
- Swap 97 and 68 (10, 26, 75, 68, 97)
SECOND PASS:
- Swap 75 and 68 (10, 26, 68, 75, 97)
THIRD PASS (we moved data so needs to be done again) -
- Change nothing.
- Three passes
What happens in a merge sort?
Example - Rearrange (75, 10, 26, 97, 68) using a merge sort.
What happens in an insertion sort?
Use an insertion sort to sort: 75, 10, 26, 97, 68
SHOW EACH INSERTION!