CSE 101 Tutorial 2 Sol
CSE 101 Tutorial 2 Sol
Note:
1) In case of any doubts, please put your query in the group, or you can reach out to us on
teams as well ([email protected] & [email protected]).
2) For more info on substitution method and better understanding of second question, please also
refer Chapter 4, Divide and Conquer (Page 90, Introduction to Algorithms, Thomas H. Cormen)
3) Q2, try taking 17 as constant, and you will see the guess you assumed wont be visible, that is
why 34 has been taken.
4) Q5, you can try like Q4, levels you will get for slow recursion i.e. n/2 will be log2(n/c).
Q1 So the guess we have is T(n) = O(n2), from the definition of Big O, we have
T(n) <= cn2 ---------------1
Substituting the above in recurrence, we get
T(n) = T(n-1) + n <= c(n-1)2 + n <= cn2- 2cn + c + n <= cn2 + n (1-2c) + c
To hold equation 1, we should have some c so that 1 holds true always, if c >= ½ then we can see
that goes well, hence guess sounds good.
Q6. Solve below recurrences by Master’s Theorem if applicable –
i) T(n) = 3T(n/2) + n2
a=3 and b=2, f(n) = n2
Computing nlogba ≅ n1.5, that can be easily seen not to satisfy under case
1 and case 2 of Master’s theorem, as n2, cannot be bounded rather it
bounds i.e. case 3 falls in.
So, T(n) = θ(n2)
iii) T(n) = 2T(n/2) + n / logn [Having a doubt on this one, once I am sure
will update]