ISRO Scientist/Engineer CSE 2017Algorithms › Time Complexity and Recurrences
ISRO Scientist/Engineer CSE 2017 PYQ: The recurrence relation that arises in relation with the complexity of binary search is:
The recurrence relation that arises in relation with the complexity of binary search is:
- A$T(n) = 2T\left(\frac{n}{2}\right)+k, \text{ k is a constant }$
- B$T(n) = T\left(\frac{n}{2}\right)+k, \text{ k is a constant }$Correct answer
- C$T(n) = T\left(\frac{n}{2}\right)+\log n$
- D$T(n) = T\left(\frac{n}{2}\right)+n$
Answer
(B) $T(n) = T\left(\frac{n}{2}\right)+k, \text{ k is a constant }$
Approach
Binary search compares the target with the middle element, then discards one half and recurses on the remaining half. This gives one subproblem of size n/2 plus a constant amount of work per level, i.e. T(n) = T(n/2) + k.
Reviewed by ISRO IQ Editorial Team.