I am trying to analyze this recurrence relation in terms of Big Theta. Why $\Theta(N^2)$ is wrong answer? My thought is that while the answer for a similar problem is $u_k=u_{k−1}+1 = \Theta(N)$ then the answer for the problem above must be $\Theta(N^2).$ I am following the method of finding the $\Theta$ in a non recurrence function.
-
Well following your pattern wouldn't $u_k=u_{k-1}+k$ be $\Theta(N^2)$ and $u_k=u_{k-1}+k^2$ be $\Theta(N^3)$ – kingW3 Feb 04 '17 at 15:53
2 Answers
To see for yourself, expand your recurrence relation:
$$ \begin{align} u_k &= u_{k-1} + k^2 \\ &= \underbrace{u_{k-2} + (k-1)^2}_{= u_{k-1}} + k^2 \\ &= \underbrace{u_{k - 3} + (k - 2)^2}_{= u_{k-2}} + (k - 1)^2 + k^2 \\ &= \underbrace{u_{k - 4} + (k - 3)^2}_{= u_{k-3}} + (k-2)^2 + (k - 1)^2 + k^2 \\ & \vdots \\ u_k &= u_0 + \sum_{i=0}^k (k - i)^2 \\ &= u_0 + \frac{k(k + 1)(2k + 1)}{6} \\ &= u_0 + \frac{k^3 + \mbox{terms dominated by } k^3}{6} \end{align} $$ which, assuming $u_0$ takes constant time, is essentially $\mathcal{\Theta}(k^3)$. Remember that $T(n) = \Theta(n^3)$ is implied by
$$ c_1 n^3 \leq T(n) \leq c_2 n^3 $$ for appropriately small $c_1$ and large $c_2$, which is the case here.

- 3,840
-
Thanks for the reply. It is helpful but I am not getting why the summation ∑i=0k(k−i)2 and also I don't understand how you end with Θ(k3). Can you explain it a bit further? – peterpanx Feb 04 '17 at 16:17
-
@peterpanx I added a few more terms in the answer, if it helps you. To see why the final sum appears, ask yourself: how many times do you have to "reduce" $k$ until you reach $0$? For the $i$'th of those steps, you get a quadratic cost $(k - i)^2$. Those costs make up the final sum. – VHarisop Feb 04 '17 at 16:22
-
yes it is much clearer now. According to this rules here http://math.stackexchange.com/a/551391/413117 the summation should be k(k+1)(2k+1)/6 .What it is changed here? Also,in our case which is c1 and accordingly c2? Thanks a lot again for the help! – peterpanx Feb 04 '17 at 16:36
-
@peterpanx You were right, I had a typo. I edited the answer to add the correct result. For $c_2$, observe that $k(k+1)(2k+1) / 6=\frac{2k_3+3k_2+k}{6} \leq \frac{6 k_3}{6}$ for large $k$, so you could pick $c_2 = 1$. For $c_1$, observe that $ \frac{k(k+1)(2k+1)}{6} \geq \frac{2k^3}{6} $, so you can pick $c_1 = \frac{1}{3}$. – VHarisop Feb 04 '17 at 17:00
It seems easier to me to solve the recurrence and analyze the solution.
First we try to get rid of the inhomogenity: $$ u_k = u_{k-1} + k^2 \\ $$ Then for $k+1$ we have $$ u_{k+1} = u_k + (k+1)^2 \\ $$ Then subtracting the first equation from the second and rearranging gives $$ u_{k+1} = 2 u_k - u_{k-1} + 2k + 1 \\ u_{k+2} = 2 u_{k+1} - u_k + 2k + 3 $$ and subtracting again gives $$ u_{k+2} = 3 u_{k+1} - 3 u_k + u_{k-1} + 2 \\ u_{k+3} = 3 u_{k+2} - 3 u_{k+1} + u_k + 2 $$ and finally $$ u_{k+3} = 4 u_{k+2} - 6 u_{k+1} + 4 u_k - u_{k-1} $$ or $$ u_n = 4 u_{n-1} - 6 u_{n-2} + 4 u_{n-3} - u_{n-4} $$ This is a homogeneous linear recurrence relation with constant coefficients and characteristic polynomial $$ p(t) = t^4 -4 t^3 + 6 t^2 - 4 t + 1 = (t-1)^4 $$ with four fold root $r=1$ and thus the solution is of the form \begin{align} u_n &= k_1 r^n + k_2 n r^n + k_3 n^2 r^n + k_4 n^3 r^n \\ &= k_1 + k_2 n + k_3 n^2 + k_4 n^3 \end{align} The four constants $k_i$ depend on the initial values $u_1, u_2, u_3, u_4$.
Thus $u_n = \Theta(n^3)$.

- 34,562