You are on page 1of 6

INDIAN INSTITUTE OF TECHNOLOGY ROORKEE

Data Structures and Algorithms (CSE-101)


Tutorial 2 (Solutions) Spring 23-24

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 (rishabh_v@cs.iitr.ac.in & nitin_t@cs.iitr.ac.in).
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)

ii) T(n) = 64 T(n/8) – n2 logn


Master Theorem is not applicable because of negative sign.

iii) T(n) = 2T(n/2) + n / logn [Having a doubt on this one, once I am sure
will update]

iv) T(n) = 2T(n/4) + n0.51


a=2 and b=4, f(n) = n0.51
Computing nlogba ≅ n0.5, that can be easily seen not to satisfy under case
1 and case 2 of Master’s theorem.
Case 3 fits well for ∈ <= 0.01, so T(n) = θ (n0.51)

v) T(n) = 16 T(n/4) +nn


Master theorem is not applicable here, as nn, does not fit for any of the
three cases.

vi) T(n) = 5T(n/5) + √n


Case 1 satisfies here as f(n) = √n = O(nlogba-∈) = O(n1-∈) (let ∈ = 0.1)
So, T(n) = θ(n)

You might also like