2

I am working on proving the time complexity for the following problem, but believe I am stuck:

$$T(n) = 2T(n/3 + 1) + n$$

I have checked out this link here on time complexity on cs.stackexchange

However, I still cannot seem to find the answer. Using this proof from a Dartmouth course:

$a = 2, b = 3, c = 1$

In this case, I know logb a is .63, which is less than 1, so the complexity is $Θ(n)$. However, I don't know how to prove that.

I am trying to practice with the methods that I "know" - Master Theorem, Substitution, Iteration, or a Recursion Tree. And using one of those 4 methods, I can't find a way to prove the complexity is $Θ(n)$, even though I know that's the answer.

Would anyone be able to assist?

David Richerby
  • 82,470
  • 26
  • 145
  • 239
artemis
  • 225
  • 4
  • 15

2 Answers2

2

You can use the Akra–Bazzi theorem, a generalization of the master theorem.

Using the notations in the Wikipedia page:

  • $g(x) = x$
  • $k = 1$
  • $a_i = 2$
  • $b_i = 1/3$
  • $h_1(x) = 1$ (in fact, probably $h_1(x)$ is a bit different, since $n/3+1$ isn't always an integer)
  • $x_0$ is a constant which is missing from your recurrence relation

You can easily check that all conditions of the theorem hold. To get the asymptotics, we first compute the value of $p$, which is the solution to $2(1/3)^p = 1$, that is, $p = \log_3 2$. Next, we calculate the integral appearing in the answer formula: $$ \int_1^x \frac{u}{u^{p+1}} \, du = \int_1^x u^{-p} \, du = \frac{x^{1-p}-1}{1-p}. $$ We conclude that $$ T(x) = \Theta\left(x^p\left(1 + \frac{x^{1-p}-1}{1-p}\right)\right) = \Theta(x^p + x) = \Theta(x^{\max(p,1)}). $$ Since $p < 1$, the answer is $T(x) = \Theta(x)$.

More generally, the Akra–Bazzi theorem shows that the master theorem applies even when the applications of $T$ on the right-hand side of the recurrence are off by a small amount (at most $O(x/\log^2 x)$).

Yuval Filmus
  • 280,205
  • 27
  • 317
  • 514
1

You could try to show by induction that T(n) ≤ 5n. We have T(n) = 2 T (n/3 + 1) + n ≤ 10(n/3 + 1) + n = 4 1/3 n + 10 ≤ 5n if n ≥ 15, so if you show T(k) ≤ 5k for some range n/3 ≤ k < n, n ≥ 15, the problem is solved.

gnasher729
  • 32,238
  • 36
  • 56