7
$\begingroup$

I've been tasked with solving some recurrence relations, and I've been running into trouble with so called 'chip & conquer' relations.

Here are some example problems:

$$T(n) = T(n-5) + cn^2$$

and

$$T(n) = T(n-2) + \log{n}$$

I'm supposed to be giving an answer in $\Theta$ notation. How do I go around and solving relations like these?

$\endgroup$

migrated from stackoverflow.com Jul 10 '12 at 15:41

This question came from our site for professional and enthusiast programmers.

4
$\begingroup$

For simplicity, let's assume that $5$ divides $n$ and that $n/2=n-5k$ for some integer $k>0$.

$$ \begin{align*} T(n) &= T(n-5) + cn^2 \\ T(n) &= cn^2 + c(n - 5)^2 + c(n - 10)^2 + c(n - 15)^2 + ... + c5^2 + c0^2 \\ &= c(n^2 + (n - 5)^2 + (n - 10)^2 + (n - 15)^2 + ... + 5^2 + 0^2) \\ &\ge c(n^2 + (n - 5)^2 + (n - 10)^2 + (n / 2)^2) \ge c(n / 2)(1 / 5)(n / 2)^2) \\ &= cn^3 / 40 = (c / 40)n^3 \\ &= \Omega(n^3) \\ T(n) &= cn^2 + c(n - 5)^2 + c(n - 10)^2 + c(n - 15)^2 + ... + c5^2 + c0^2 \\ &\le c(n / 5)n^2 \le cn^3 \\ &= O(n^3) \\ \end{align*} $$

We conclude that $T(n) = \Theta(n^3)$.


Let's assume for simplicity that $n/2 = n-2k$ for an integer $k>1$.

$$ \begin{align*} T(n) &= T(n-2) + \log n = \log n + \log(n - 2) + \log(n - 4) + ... + \log(4) \\ &\ge \log n + \log(n - 2) + \log(n - 4) + ... + \log(n / 2) \ge (n / 2)log(n / 2) \\ &= \Omega(n \log n) \\ T(n) &= T(n-2) + \log n = \log n + \log(n - 2) + \log(n - 4) + ... + \log(4) \\ &\le (n / 2) \log n \\ &= O(n \log n) \\ \end{align*} $$

We conclude that $T(n)=\Theta(n \log n)$.

$\endgroup$
0
$\begingroup$

Expand the recurrence and sum it up.

Example 1:

$$ \begin{align*} T(n) &= T(n-5) + O(n^2) = T(n-10) + O(n^2) = \dots \\ &= T(0) + \{\text{\(n/5\) terms, each \(O(n^2)\)}\} \end{align*} $$

Now let's say $T(0) = c$. This would be generally given in the question.

so this would sum to $(n/5).O(n^2) = O(n^3)$

Example 2:

$$ \begin{align*} T(n) &= T(n-2)+\log n = T(n-4)+\log(n-2) + \log(n) = \dots \\ &= T(0) + \log(n-2^k) + \dots + log(n) = c + \log(n-2^k) + \dots + \log(n-2) + \log(n) \\ &= c + n \log(n) \end{align*} $$

$\endgroup$
  • $\begingroup$ It was supposed to be +cn^2 not =cn^2. Silly typos! $\endgroup$ – user906153 Apr 25 '12 at 2:42

Your Answer

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