1 1 vote What is the time complexity of following code?def fun(n): count = 0 i = n while i > 0: for j in range(i): count += 1 i //= 2 return count$\Theta(N \log N)$$\Theta(N)$$\Theta(\log N)$$\Theta\left(N^{2}\right)$ Algorithms goclasses_da_dsa_tw2 goclasses algorithms asymptotic-notations time-complexity two-marks + – GO Classes 266 views answer comment Share Follow Print 0 reply Please log in or register to add a comment.
2 2 votes Answer is Option BUnroll the inner for loop .Time complexity will be $n+\frac{n}{2}+\frac{n}{4}+.........+\frac{n}{2^{k}}$ where $k=\log _{2}n$T.C = $\Theta \left ( 2^{k} \right ) = \Theta \left ( n \right )$ GO Classes answered Sep 16, 2024 GO Classes comment Share Follow 0 reply Please log in or register to add a comment.