Sorting Exercises
- What is a visualization that you have found to be helpful?
- Exchange Sorting Algorithms
- Discuss with your neighbor(s) how the following sorting algorithms work:
- Insertion sort
- Bubble sort
- Selection sort
-
Trace the following algorithms sorting the following array:
Write the contents of the array according to each specified criterion.
For swaps, put a star above the number(s) that are swapped.
- Insertion sort (at the end of each iteration of the outer loop)
- Bubble sort (after each swap)
- Selection sort (after each swap)
- Write down the major steps for the following sorting algorithms:
- Insertion sort
- Bubble sort
- Selection sort
- Write down the following properties for the stated sorting algorithms:
|
Best-case Big-Oh |
Average-case Big-Oh |
Worst-case Big-Oh |
Stable? |
Extra Space |
Distinguishing Features |
Insertion Sort |
|
|
|
|
|
|
Bubble Sort |
|
|
|
|
|
|
Selection Sort |
|
|
|
|
|
|
- Discuss with your neighbor(s) how the following sorting algorithms work:
- Mergesort
- Quicksort
- Heapsort
- How are each of the following animations wrong / inaccurate (compared the videos)?
- Mergesort
- Quicksort
- Heapsort
-
Trace the following algorithms sorting the following array:
Write the contents of the array according to each specified criterion. For swaps, put a star above the number(s) that are swapped.
- Mergesort (at the end of each merge)
- Quicksort (after each swap, including swapping the same element in the same place and the swap for the pivot) (choose the pivot as described in the video)
- Heapsort (at the end of each iteration of each loop)
- For the two recursive sorting algorithms in the previous problem (Mergesort and Quicksort), trace the method calls and their parameters as was done in the videos for the same array as above (including indenting to indicate the call stack level).
- Write down the following properties for the stated sorting algorithms:
|
Best-case Big-Oh |
Average-case Big-Oh |
Worst-case Big-Oh |
Stable? |
Extra Space |
Distinguishing Features |
Mergesort |
|
|
|
|
|
|
Quicksort |
|
|
|
|
|
|
Heapsort |
|
|
|
|
|
|
- Discuss with your neighbor(s) how the following sorting algorithms work:
- Bucket sort
- Radix sort
-
Trace the following algorithms sorting the following array:
2152 |
3180 |
725 |
1781 |
1248 |
4590 |
2990 |
633 |
Write the contents of the array according to each specified criterion.
- Bucket sort (show the buckets)
- Radix sort (at the end of each iteration)
- Write down the following properties for the stated sorting algorithms:
|
Best-case Big-Oh |
Average-case Big-Oh |
Worst-case Big-Oh |
Stable? |
Extra Space |
Distinguishing Features |
Bin sort |
|
|
|
|
|
|
Radix sort |
|
|
|
|
|
|
Last Modified: