$A({n})=A(\lfloor{n/2} \rfloor)+n^2$ for $n>1$

$A({n})=1$ for $n=0,1$

Will above recursion ends in $\Theta(n^2)$ time?


If by "ends in $\Theta(n^2)$ time" you mean that the (naive) evaluation of $A(n)$ requires $\Theta(n^2)$ evaluations of $A$, then no. In fact, it takes only $\lfloor \log_2 n \rfloor + 1 = \Theta(\log n)$ evaluations (for $n \ge 2$).

Specifically, it's easy to show by induction on $k$ that naive evaluation of $A(n)$ takes $k$ evaluations for all $2^{k-1} \le n < 2^k$, $k \ge 2$.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.