Algorithm Analysis/Merge Sort
From charlesreid1
Master Theorem Analysis
Merge sort has the recurrence relation:
$ T(n) = 2 T \left( \frac{n}{2} \right) + f(n) $
due to the fact that each split operation splits the array of data into 2 parts of size $ \frac{n}{2} $.
The work done merging (the f(n) on the right) is linear, so $ f(n) = O(n) $.
Now we can apply the Master Theorem. The quantity c is:
$ c = \log_b{(a)} = \log_2{(2)} = 1 $
Therefore $ O(n^c) = O(n) $
If we examine the 3 cases, we can see that we fall into Case 2:
$ f(n) = \Theta \left( n^{\log_b{(a)}}) \log^{k}{(x)} \right) $
with k = 0. Then that implies:
$ T(n) = \Theta(n \log^{k+1}{(n)}) $
Therefore, overall, merge sort is Theta(n log n):
$ T(n) = \Theta( n \log{n} ) $
Flags
| Algorithms Part of Computer Science Notes
Series on Algorithms
Algorithms/Sort · Algorithmic Analysis of Sort Functions · Divide and Conquer · Divide and Conquer/Master Theorem Three solid O(n log n) search algorithms: Merge Sort · Heap Sort · Quick Sort Algorithm Analysis/Merge Sort · Algorithm Analysis/Randomized Quick Sort
Algorithms/Search · Binary Search · Binary Search Modifications
Algorithms/Combinatorics · Algorithms/Combinatorics and Heuristics · Algorithms/Optimization · Divide and Conquer
Algorithms/Strings · Algorithm Analysis/Substring Pattern Matching
Algorithm complexity · Theta vs Big O Amortization · Amortization/Aggregate Method · Amortization/Accounting Method Algorithm Analysis/Matrix Multiplication
Estimation Estimation · Estimation/BitsAndBytes
Algorithm Practice and Writeups Project Euler · Five Letter Words · Letter Coverage
|