Merge Sort
Memorize
To be memorize and the analysis.
I actually have difficulty understanding MergeSort and QuickSort…
Update Jan19 2024: I get Merge Sort now. A type of Divide and Conquer. Prof demonstrated in class CS341.
High-level idea for Merge Sort: Input: Array of integers
- Step 1: Split into two subarrays: consists of the first elements in and consists of the last elements in .
- Step 2: Recursively run Merge Sort on and .
- Step 3: After and are sorted, use function Merge to merge two sorted arrays into one single sorted array.
Pseudocode:
Merge takes time for merging elements.
Analysis of Merge Sort
Time complexity: Recurrence Relation
- growth rate
- Best Case
- Worst Case
Don’t really understand this sloppy recurrence.
What's the recursion tree method?
Solving the Exact Recurrence
- The recursion tree method finds the solution of the exact recurrence when (it is in fact a proof for these values of ).
- If this solution is expressed as a function of using -notation, then we obtain the complexity of the solution of the exact recurrence for all .
- This is not a proof, however. If a real mathematical proof is required, then it is necessary to use induction.