Daniel Sutantyo, Department of Computing, Macquarie University
6.2 - Substitution Method
6.2 - Substitution Method
6.2 - Substitution Method
\(T(n) = \begin{cases} \Theta(1) &\text{if $n = 1$}\\ 2T(n/2) + cn &\text{if $n > 1$} \end{cases}\)
6.2 - Substitution Method
\(T(n) = \begin{cases} 1 &\text{if $n = 1$}\\ 2T(n/2) + cn &\text{if $n > 1$} \end{cases}\)
6.2 - Substitution Method
6.2 - Substitution Method
\(T(n) = \begin{cases} 1 &\text{if $n = 1$}\\ 2T(n/2) + cn &\text{if $n > 1$} \end{cases}\)
6.2 - Substitution Method
once you got to \(n = 4\) onward, you don't need to depend on \(T(1)\) anymore
\(T(n) = \begin{cases} 1 &\text{if $n = 1$}\\ 2T(n/2) + cn &\text{if $n > 1$} \end{cases}\)
6.2 - Substitution Method
\(T(n) = \begin{cases} 1 &\text{if $n = 1$}\\ 2T(n/2) + cn &\text{if $n > 1$} \end{cases}\)
\(T(2k) = 2*T(k) + 2ck\)
\(\le 2ck\log k + 2ck\)
(from the recurrence)
(from the induction hypothesis)
\(\le 2ck\log 2k + 2ck\)
6.2 - Substitution Method
\(T(n) = \begin{cases} 1 &\text{if $n = 1$}\\ 2T(n/2) + cn &\text{if $n > 1$} \end{cases}\)
6.2 - Substitution Method
\(T(n) = \begin{cases} 1 &\text{if $n = 1$}\\ 2T(n/2) + cn &\text{if $n > 1$} \end{cases}\)
\(T(k) = 2*T(\frac{k}{2}) + ck\)
\(\le ck\log \frac{k}{2} + ck\)
(from the recurrence)
(from the induction hypothesis)
\(= ck\log k - ck\log2 + ck = ck\log k\)
6.2 - Substitution Method
(since we're using log base 2)
\(T(n) = \begin{cases} 1 &\text{if $n = 1$}\\ 2T(n/2) + cn &\text{if $n > 1$} \end{cases}\)
\(T(n) = \begin{cases} 1 &\text{if $n \le 2$}\\3T(n/3) + 2 &\text{if $n > 2$} \end{cases}\)
6.2 - Substitution Method
6.2 - Substitution Method
\(T(n) = \begin{cases} 1 &\text{if $n \le 2$}\\3T(n/3) + 2 &\text{if $n > 2$} \end{cases}\)
6.2 - Substitution Method
\(T(n) = \begin{cases} 1 &\text{if $n \le 2$}\\3T(n/3) + 2 &\text{if $n > 2$} \end{cases}\)
\(T(k) = 3T(k/3) + 2\)
\(\le ck + 2\)
(from the recurrence)
(from the induction hypothesis)
can we say \(T(k) \le ck\) ?
\(= ck + 2\)
6.2 - Substitution Method
\(T(n) = \begin{cases} 1 &\text{if $n \le 2$}\\3T(n/3) + 2 &\text{if $n > 2$} \end{cases}\)
\(T(k) = 3T(k/3) + 2\)
\(\le 3(ck/3 - d) + 2\)
(from the recurrence)
(from the induction hypothesis)
can we say \(T(k) \le ck - d\) now? Yes, for \(d \ge 1\)
\(= ck -3d + 2\)
so \(T(n) \le cn - 1\), hence \(T(n)= O(n)\)
6.2 - Substitution Method
\(T(n) = \begin{cases} 1 &\text{if $n \le 2$}\\3T(n/3) + 2 &\text{if $n > 2$} \end{cases}\)
\(T(n) = \begin{cases} 1 &\text{if $n = 1$}\\ 2T(n/2) + cn &\text{if $n > 1$} \end{cases}\)
\(T(n) = \begin{cases} 1 &\text{if $n \le 3$}\\3T({n/4}) + n^2 &\text{if $n > 3$} \end{cases}\)
6.2 - Substitution Method
6.2 - Substitution Method
\(T(n) = \begin{cases} 1 &\text{if $n \le 3$}\\3T({n/4}) + n^2 &\text{if $n > 3$} \end{cases}\)
6.2 - Substitution Method
\(T(k) = 3T(\frac{k}{4}) + k^2\)
\(\le 3ck^2/16 + k^2\)
(from the recurrence)
(from the induction hypothesis)
\(= (3c/16+1)k^2\)
\(T(n) = \begin{cases} 1 &\text{if $n \le 3$}\\3T({n/4}) + n^2 &\text{if $n > 3$} \end{cases}\)
Therefore \(T(k) \le c k^2\) with \(c = 2\) since \(3c/16+1 < 2\), hence \(T(k) = O(k^2)\)
6.2 - Substitution Method