Master Theorem Examples
Understand how to apply the master theorem to solve recurrence relations for algorithm time complexities. Learn through examples including merge sort, binary search, and tree traversals, focusing on identifying cases and calculating final complexity expressions. This lesson builds skills in evaluating algorithm efficiency using the master theorem within Go programming.
Examples
The following are some examples of the master theorem. Let’s look at them one by one.
Example 1
This is the case of merge sort. Its time complexity is = + .
Solution
In this example, and are both equal to 2. So, = = 1 which means that = n = . That means case 2 is applied and = . Its final time complexity is = .
Example 2
This is a case of binary search. Its time complexity is = + .
Solution
In this example, is equal to 1 and is equal to 2. So, = = 0 which means that = k = . That means case 2 is applied and = ...