From charlesreid1

No edit summary
(Automated edit (via update-page on MediaWiki MCP Server))
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
=Master Theorem Analysis=
=Master Theorem Analysis=


Line 7: Line 9:
</math>
</math>


Because the work done merging (the f(n) on the right) is linear, <math>f(n) = O(n)</math>.
due to the fact that each split operation splits the array of data into 2 parts of size <math>\frac{n}{2}</math>.
 
The work done merging (the f(n) on the right) is linear, so <math>f(n) = O(n)</math>.


Now we can apply the [[Master Theorem]]. The quantity c is:
Now we can apply the [[Master Theorem]]. The quantity c is:
Line 20: Line 24:


<math>
<math>
f(n) = \Theta \left( n^{\log_b{(a)}}) \log^{k}{(x)} \right)
f(n) = \Theta \left( n^{\log_b{(a)}} \log^{k}{(x)} \right)
</math>
</math>


Line 34: Line 38:
T(n) = \Theta( n \log{n} )
T(n) = \Theta( n \log{n} )
</math>
</math>


=Flags=
=Flags=

Latest revision as of 23:16, 5 June 2026


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