2 2 votes What is the time complexity of the following recursive function? int DoSomething (int n) { if (n <= 2) return 1; else for( i=1 to sqrt{log n} ) doconstantwork() // O(1) return (DoSomething (floor (sqrt(n))) + n); } $\Theta(n \log n)$ $\Theta(\sqrt{\log n})$$\Theta(\log n)$ $\Theta(n)$ Algorithms goclasses algorithms goclasses-cs-dpp goclasses-cs-dpp-day-65 goclasses-algorithms-practice-questions + – 🚩 Edit necessary | 👮 Rhino | 💬 “semicolon missing in line 6” GO Classes 460 views answer comment Share Follow Print 0 reply Please log in or register to add a comment.
Best answer 2 2 votes $\mathrm{T}(\mathrm{n})=\mathrm{T}(\sqrt{n})+\sqrt{\log n}$.Solution sketch:Let $\mathrm{n}=2^{\mathrm{m}} \rightarrow \mathrm{T}\left(2^{\mathrm{m}}\right)=\mathrm{T}\left(2^{\mathrm{m} / 2}\right)+\sqrt{m}$. Let $\mathrm{S}(\mathrm{m})=\mathrm{T}\left(2^{\mathrm{m}}\right)$then$$\mathrm{S}(\mathrm{~m})=\mathrm{S}(\mathrm{~m} / 2)+\sqrt{m}$$Expansion:$$\mathrm{S}(\mathrm{~m})=\sqrt{m}+\sqrt{m / 2}+\sqrt{m / 4}+\cdots$$This behaves like a decreasing geometric series scaled by $\sqrt{m}$ So total $=\Theta(\sqrt{m})$ Back-substitute $m=\log n$$$\mathrm{T}(\mathrm{n})=\Theta(\sqrt{\log n}) .$$ GO Classes answered Aug 23, 2025 • selected Aug 25, 2025 by GO Classes GO Classes comment Share Follow 0 reply Please log in or register to add a comment.
0 0 votes answer is b Gaurav_sharma 1 answered Aug 23, 2025 Gaurav_sharma 1 comment Share Follow 0 reply Please log in or register to add a comment.