- #1
apiwowar
- 96
- 0
i found the recursive relation which is T(n) = 1 + t(n/2)
after a couple of substitutions i found the pattern which is T(n) = 2i-1 + T(n/ 2i)
i chose i = log2 n and then when i plugged it in i got
T(n) - 2log2(n -1) + T(1)
but doesn't the first part simplify to n-1?
the complexity of binary search is O(logn)
where did i mess up?
after a couple of substitutions i found the pattern which is T(n) = 2i-1 + T(n/ 2i)
i chose i = log2 n and then when i plugged it in i got
T(n) - 2log2(n -1) + T(1)
but doesn't the first part simplify to n-1?
the complexity of binary search is O(logn)
where did i mess up?