in the Answer pdf :
Answer is b) O(N)
Explanation: For a input integer n, the innermost statement of fun() is executed following
times.
n + n/2 + n/4 + … 1
So time complexity T(n) can be written as
T(n) = O(n + n/2 + n/4 + … 1) = O(n)
My Doubt :
you have corrrectly stated T(n) = O(n +n/2…) right?
how is that equal to n???
(as per your bin, search explanation) shouldnt :
n + n/2 +n/4 + n/8 …n/(2^k) where k is number of steps?
and since,
n/(2^k) = 1
n = 2^k
k = log(n)???
so how did you equate
n + n/2 +n/4 + n/8 …….n/(2^k) = O(n) ???
Please elucidate…
Thank you !