2081 5

CSC325 · 2081 · 5 marks

Solve the following recurrence relations using master's method. 1. T(n) = 2Tleft(fracn2right) + n3, n > 1;quad T(n) = 1, n = 1 2. T(n) = 2Tleft(fracn4right) + 1, n > 1;quad T(n) = 1, n = 1

Solve the following recurrence relations using master's method.

  1. $T(n) = 2T\left(\frac{n}{2}\right) + n^3,\ n > 1;\quad T(n) = 1,\ n = 1$

  2. $T(n) = 2T\left(\frac{n}{4}\right) + 1,\ n > 1;\quad T(n) = 1,\ n = 1$

[5]

Design and Analysis of AlgorithmsChapter 1: Foundation of Algorithm AnalysisSolving RecurrencesNumerical: Master's theorem recurrence

Solving Recurrence Relations Using Master's Method

Master Method Framework

For $T(n) = aT\left(\frac{n}{b}\right) + f(n)$ with $a \geq 1$, $b > 1$:

Compute the critical exponent $\log_b a$ and compare $f(n)$ with $n^{\log_b a}$:

CaseConditionResult
1$f(n) = O(n^{\log_b a - \epsilon})$, $\epsilon > 0$$T(n) = \Theta(n^{\log_b a})$
2$f(n) = \Theta(n^{\log_b a})$$T(n) = \Theta(n^{\log_b a}\log n)$
3$f(n) = \Omega(n^{\log_b a + \epsilon})$, $\epsilon > 0$ (+ regularity)$T(n) = \Theta(f(n))$

Given Data

  • Recurrence 1: $T(n) = 2T(n/2) + n^3$, $n>1$; $T(1)=1$
  • Recurrence 2: $T(n) = 2T(n/4) + 1$, $n>1$; $T(1)=1$

Problem 1: $T(n) = 2T\left(\dfrac{n}{2}\right) + n^3$

Parameters: $a = 2,\ b = 2,\ f(n) = n^3$

Critical exponent: $$\log_b a = \log_2 2 = 1 \implies n^{\log_b a} = n$$

Compare: $f(n) = n^3$ vs $n^1$

Since $n^3 = \Omega(n^{1+\epsilon})$ with $\epsilon = 2 > 0$, this is Case 3.

Regularity check: $$a,f!\left(\frac{n}{b}\right) = 2\left(\frac{n}{2}\right)^3 = \frac{n^3}{4} \leq c,n^3,\quad c=\tfrac14 < 1 \ \checkmark$$

Result: $$\boxed{T(n) = \Theta(n^3)}$$


Problem 2: $T(n) = 2T\left(\dfrac{n}{4}\right) + 1$

Parameters: $a = 2,\ b = 4,\ f(n) = 1 = n^0$

Critical exponent: $$\log_b a = \log_4 2 = \frac{1}{2} \implies n^{\log_b a} = \sqrt{n}$$

Compare: $f(n) = n^0$ vs $n^{1/2}$

Since $n^0 = O(n^{1/2 - \epsilon})$ with $\epsilon = \tfrac12 > 0$, this is Case 1.

Result: $$\boxed{T(n) = \Theta(\sqrt{n})}$$


Summary

Recurrence$\log_b a$$f(n)$CaseSolution
$2T(n/2)+n^3$$1$$n^3$3$\Theta(n^3)$
$2T(n/4)+1$$1/2$$1$1$\Theta(\sqrt{n})$

Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.