We advise you to study in the following order:
-
Begin by understanding 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 covered in class 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 (recent) previous exams:
- Midterm Exam - Fall 2021: Question 4 (solution)
- First Exam - Fall 2022: Question 2 (solution)
- First Exam - Spring 2022: Question 2 (solution)
-
Practice using the advanced exercises at the end of the sorting slides. Here is a video explaining the answers.
-
Practice using old previous exams