Master Theorem for Decreasing Function
Recurrence Relation for Decreasing Function
Mathematically speaking, the master theorem provides a solution to the recurrence relation. Let's learn how we can find the recurrence relation for a decreasing function.
Suppose we have a program like this.
def test(n):
if n > 0:
for i in range(1, n+1):
print(n)
test(n-1)If the test() function takes T(n) time to execute, then

From the image, we can say,
Solving Recurrence Relation with Master Theorem
To solve an equation using recurrence relation for a decreasing function, the function must be in the following format:
Now, let's observe the equation for three different cases:
Case 1: a = 1
Case 2: a > 1
Case 3: a < 1
Let's see some examples of the calculating time complexity of decreasing function.
Example 1
The recurrence relation of the decreasing function we previously wrote is:
Now let's calculate its time complexity using the master theorem.
Step 1: Comparing the recurrence relation with the general form.
The general form of T(n) is:
Step 2: Modifying recurrence relation to match the general form.
Step 3: Finding a, b, and k checking if the master theorem is possible
a = 1
b = 1
k = 1Since a > 0, b > 0, and , the master theorem is possible.
Step 4: Comparing a and 1 and applying the matching rule
Here,
a = 1
k = 1Since a = 1, let's apply the formula to find the time complexity for this scenario.
Example 2
The recurrence relation of the dividing function we previously wrote is:
Now let's calculate its time complexity using the master theorem.
Step 1: Comparing the recurrence relation with the general form.
The general form of T(n) is:
Step 2: Modifying recurrence relation to match the general form.
Step 3: Finding a, b, and k checking if the master theorem is possible
a = 2
b = 1
k = 0Since a > 0, b > 0, and , the master theorem is possible.
Step 4: Comparing a and 1 and applying the matching rule
Here,
a = 2
k = 0Since a > 1, let's apply the formula to find the time complexity for this scenario.
Example 3
The recurrence relation of the dividing function we previously wrote is:
Now let's calculate its time complexity using the master theorem.
Step 1: Comparing the recurrence relation with the general form.
The general form of T(n) is:
Step 2: Modifying recurrence relation to match the general form.
Step 3: Finding a, b, and k checking if the master theorem is possible.
Since a > 0, b > 0, and , the master theorem is possible.
Step 4: Comparing a and 1 and applying the matching rule
Here,
Since a < 1, let's apply the formula to find the time complexity for this scenario.
Comments
Post a Comment