We advise you to study in the following order:
-
Begin by understanding everything in the slides (ignore for now the Advanced Exercises that are at the end of the sorting slides.)
-
Solve the following tracing question:
Fill out the following table with the exact number of operations:
swaps/shifts and data compares (DCs).
Assume the algorithm implementations in the slides, where:
• Bubble Sort uses a "swapped" flag to stop when the array gets sorted.
• Selection Sort does not swap an element with itself.
|----------------|----------------|----------------|-------------|
| | Selection Sort | Insertion Sort | Bubble Sort |
|----------------|----------------|----------------|-------------|
| `1 2 3 4 5` | Swaps = | Shifts = | Swaps = |
| | DCs = | DCs = | DCs = |
|----------------|----------------|----------------|-------------|
| `5 4 3 2 1` | Swaps = | Shifts = | Swaps = |
| | DCs = | DCs = | DCs = |
|----------------|----------------|----------------|-------------|
| `5 1 2 3 4` | Swaps = | Shifts = | Swaps = |
| | DCs = | DCs = | DCs = |
|----------------|----------------|----------------|-------------|
| `1 5 4 3 2` | Swaps = | Shifts = | Swaps = |
| | DCs = | DCs = | DCs = |
|----------------|----------------|----------------|-------------|
-
Practice using the worksheets:
-
Practice using the advanced exercises at the end of the sorting slides (most of these exercises are already in the worksheets). Here is a video explaining the answers.
-
Check out how (recent) previous exams look like (most of the questions are already in the worksheets):
- Midterm Exam - Fall 2021: Question 4 (solution)
- First Exam - Fall 2022: Question 2 (solution)
- First Exam - Spring 2022: Question 2 (solution)
- First Exam - Spring 2023: Question 2 (+Question 4) (solution)
-
If you are still looking for more questions, you can look at old previous exams