Consider this recurrence relation, $$T(n)=T(n-\sqrt{n})+1$$ I try to show that $T(n)=O(\sqrt{n})$.
Also, I read this link, but my question is, can I claim that, at each step $n$ decreased by at least $\sqrt{\frac{n}{2}}$ to reach $\frac{n}{2}$?
Computer Science Stack Exchange is a question and answer site for students, researchers and practitioners of computer science. It only takes a minute to sign up.
Sign up to join this communityConsider this recurrence relation, $$T(n)=T(n-\sqrt{n})+1$$ I try to show that $T(n)=O(\sqrt{n})$.
Also, I read this link, but my question is, can I claim that, at each step $n$ decreased by at least $\sqrt{\frac{n}{2}}$ to reach $\frac{n}{2}$?
I'm assuming that the base case is $T(n)=1$ for $n\le 1$. If you accept the fact that $T(\cdot)$ is an increasing function, you can show by induction on $m \ge 1$ that $T(m^2) < 2m$.
If $m \le 1$ then the claim is trivially true. Assume now that the claim holds for $m \ge 1$. You have: $$ \begin{align*} T((m+1)^2) &\le T((m+1)^2 - (m+1)) + 1 = T(m^2 + 2m +1 - m-1) +1 \\ &= T(m^2 + m) + 1 = T(m^2 + m -\sqrt{m^2+m})+2\\ &\le T(m^2)+2 < 2m+2=2(m+1). \end{align*} $$
Then $T(n) = O(\sqrt{n})$ follows by choosing $m = \lceil \sqrt{n} \rceil$ since $T(n) \le T(m^2) < 2(m+1) < 2(\sqrt{n} +2) = O(\sqrt{n})$.