Some Ideas for Sorting Algorithms
Insertion Sort
- Make the first number a list by itself – it is already sorted
- “Insert” each number, one at a time, into the correct place in the list; shift the other numbers if you need to
- The list slowly “grows” in sorted order
-
Bubble Sort
- Compare each pair of numbers, one pair at a time; if the pairs are out of order, swap them.
- Keep doing this step until you go through the complete list without having to swap a single pair.
-
Exchange Sort
- Go through the list, at each step swapping the smallest number into the first slot in the list.
- Repeat this step with each successive position in the list.
-
-
-
-
Take out a piece of paper. Tear it into 5 small pieces. Write the following numbers, one on each piece of paper: 2, 17, 33, 4, 6.
Take out a second piece of paper. Write your name on it.
Write down the steps (an algorithm) to sort these 5 numbers. Note: At any point in time, you can only view and compare 2 numbers at a time.
(I’ll collect these at the end of class today. These won’t be graded.)