CSC 414 - Algorithms: Midterm II Study Guide
March 21, 2024
Prove that the following sorting algorithms are correct using proof by induction:
1. Insertion Sort
2. Merge Sort
3. Inline Merge Sort
4. Heap Sort
5. Quick Sort
6. Randomized Quick Sort
7. Tail Recursive Quick Sort
8. Bucket Sort
9. Counting Sort
10. Matrix Multiplication Algorithm
11. Square Matrix Multiplication Algorithm
12. Recursive Square Matrix Multiplication
An example proof for Bubble Sort is included below:
Bubble Sort Proof by Induction:
Inductive Hypothesis: At the end of each iteration of Bubble Sort, the largest unsorted
element is located in its correct position in the sorted portion of
the array.
First Iteration:
At the start of the first iteration, the largest element in the entire
list is in any position in the unsorted region.
During the first iteration, the algorithm performs swaps only
between adjacent elements if they're in the wrong order.
The swap therefore moves a larger element toward the end of
the list.
At the end of the first iteration, the largest element in the entire
list is correctly placed at the end of the list.
Base Case:
Assume that after the $k^{th}$ iteration, the $k$ largest elements are
correctly sorted at the end of the list.
During the $(k+1)^{th}$ iteration, the algorithm performs swaps
only between adjacent elements if they're in the wrong order.
Each swap therefore moves a larger element toward the end of
the list.
Inductive Step:
After the $(k+1)^{th}$ iteration, the $(k+1)$ largest element is
correctly placed at its final position in the unsorted region which
becomes the beginning position of the sorted region.
Therefore, the Bubble Sort algorithm is correct by Induction.