From charlesreid1

(Created page with "Merge sort has the recurrence relation: <math> T(n) = 2 T \left( \frac{n}{2} \right) + f(n) </math> Because the work done merging (the f(n) on the right) is linear, <math>f(...")
 
No edit summary
Line 1: Line 1:
=Master Theorem Analysis=
Merge sort has the recurrence relation:
Merge sort has the recurrence relation:



Revision as of 10:11, 20 July 2017

Master Theorem Analysis

Merge sort has the recurrence relation:

$ T(n) = 2 T \left( \frac{n}{2} \right) + f(n) $

Because the work done merging (the f(n) on the right) is linear, $ 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