Summary
keywords
TODO
HW
$T(n) = T(n/2) +n$
use Substitution
$T(n) = 8T(n/2) + nlogn$
Assignment document.
Exercise*
Next time
Recursion Tree Method, Substitution,
write the recursion formula
How do you reduce the size of the input?
ex. substraction, division, taking a root.
shortcut method for recurrence relation.
3. Decreasing Recurrance $T(n)=2*T(n-1)+1$
example. fibonacci, subset finding problem.
Substitution:
$T(n) = 2T(n-1)+1$
$\quad\quad=T(n-2)+1$
$\quad\quad=2T(n-2)+21+1$
$\quad\quad=2T(n-3)+221+21+1$
$\quad...$
$\quad\quad=2T(n-k)+2^{k-1}+2^{k-2}+2^{k-3}+...+2^2+2+1$
Time complexity of $O(2^n)$.
Masters Theorem
forT(n)=aT(n−b)+f(n)
where $a>0,;b>0,; f(n)= O(n^k); \text{where}; k>=0$
Case 1. $a==1;$
O(f(n)∗n)
#todo : fill out examples.
O(nkan/b)
#todo : fill out examples.
Dividing Function
For dividing functions, it is important n should never be zero in base case.
base case should not be of input size 0
Because we cannot divide by 0..
1. Dividing Recurrence $T(n)=T(n/2)+1$
T(n)={1T(n/2)+1n=1n>1. smallest valid input should be $n=1$.
How many 1's are added?
$n=2^k$
$k=\log n$
So, Time complexity is $\Theta(\log n)$
Let's use substitution method this time.
$T(n) =T(n/2)+1$
$\quad\quad=T(n/2^2)+1+1$
$\quad\quad=T(n/2^3)+1+1+1$
$\quad...$
$\quad\quad=T(n/2^k)+k$
$\quad\quad=1+\log n$
2. Dividing Recurrence $T(n) = 2T(n/2)+n$
#todo : check the picture taken and see the recursive tree method.
find each step's time complexity (A)
find the base condition, and find the layer depth. (B)
time complexity = $A * B$
#todo : write about substitution
time complexity is $\Theta(n\log n)$
Last updated