-1

Base case of $T(1)=1$

As a part of your solution establish, a pattern for what the recurrence looks like after the $k$-th iteration

Express final answer as $\Theta(n)$

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

How to solve and what is the best method to solve questions like these.

This may be an easy problem, but I run into issues with it.

David K
  • 98,388
  • Do you mean $T(n) = 2T(n/3) + n$ , or otherwise what? – G Cab Apr 14 '16 at 18:23
  • Sorry i meant im looking for Θ(n) – AlphaSquirrel Apr 14 '16 at 18:32
  • You might get a better response if you show your work (what you tried, even if you did not succeed) so that people can see what specifically you had trouble with. Then people can address that. As asked, "best method to solve questions like these" is a question that a chapter of a book might answer; it's not suitable for the format of this site. – David K Apr 14 '16 at 19:12
  • @almagest the OP is asking a question related to analysis of algorithms. In which case, we start by assuming that $n = 3^m$ for some natural number m. – user137481 Apr 14 '16 at 19:12
  • @user137481 The question was substantially different when I asked that question! But I have deleted my comment to avoid confusion. But I am still doubtful if the OP has asked the question he wanted to ask! – almagest Apr 14 '16 at 19:14
  • @almagest I believe the OP did ask the question he wanted to ask (see Azazel's answer). In the context of running times of algorithms, we generally assume $n=3^m$ WLOG. Unfortunately, this context was not included in the post. – user137481 Apr 14 '16 at 19:43

1 Answers1

1

I assume you are interested in asymptotic behaviour of $T$.

Clearly, $T(n) \geq n$

WLOG, we can assume that $n$ is a power of 3 (try to justify it formally). Let's rewrite our recursion equation as $T(n) = T(n/3) + T(n/3) + n$. Consider this to be a recursion like scheme.

Diagram

Clearly, at the first level, we have only 1 node - the total of "non recursive" part of our function, is equal to $n$. At the second level we have 2 nodes, each with weight $\frac{n}{3}$, totalling to $\frac{2}{3}n$

More generally, at level no. $k$ we have $2^k$ nodes, each with weight $\frac{n}{3^k}$, totalling to $\left(\frac{2}{3}\right)^kn$

We have exactly $\log_3(n)$ levels ($\left \lfloor \log_3(n)\right \rfloor$ in general case). So our function will be

$$T(n) = \sum_{i=0}^{\log_3(n)}\left(\frac{2}{3}\right)^in \leq \sum_{i=0}^{\infty}\left(\frac{2}{3}\right)^in = \frac{n}{1-\frac{2}{3}} = 3n$$

Hence, $T(n) = \Theta(n)$

There's also a known theorem providing the answer straight away, but where's the fun in that?

Azazel
  • 56