2

I have to solve the recurrence relation

$$T(n)=\left\{\begin{matrix} 3T\left (\frac{n}{4} \right)+n & , n>1\\ 1 &, n=1 \end{matrix}\right.$$

and prove by induction that the solution I found is right.

I found that the solution of the recurrence relation is $T(n)=O(n)$.

I started proving it like that:

  • $n=1: T(1)=1 \leq c \cdot 1 \checkmark \text{ for } c \geq 1$
  • We suppose that for any $m$, $2 \leq m <n , n>2$: $T(m) \leq c \cdot m$.
  • We want to show that the claim stands for $n$.

But, then I noticed that we do not have a formula for $T \left ( \frac{n}{4} \right)$ when $n<4$ and also when $n \neq 4^k$.

So, do we have to suppose that $n \geq 4$ and $n=4^k$ ?

If so, at which point of the proof, do I have to claim it?

evinda
  • 7,823
  • I believe the goal of the exercise as you stated it is to find an explicit expression for $T(n),n\in\mathbb{N}\backslash{0}$ $T(n)=\mathcal{O}(n)$ is not an expression of $T(n)$, as $\mathcal{O}(n)$ is not a sequence. – Hippalectryon Oct 07 '14 at 16:29
  • Do they want you to solve the recurrence, or to show that the function is $O(n)$? – Semiclassical Oct 07 '14 at 16:33
  • Firstly I have to solve the recurrence relation and then I have to prove that the relation I found is right, by using induction.

    I found $T(n)=4n-3n^{\log_4 3}$..

    – evinda Oct 07 '14 at 16:35
  • 1
    @evinda Then, why are you trying to show that it is $\mathcal{O}(n)$ ? Why would this help, as it isn't requested ? – Hippalectryon Oct 07 '14 at 16:37
  • The exercise is from the chapter, where we calculate asymptotic complexities.. :/ – evinda Oct 07 '14 at 16:39
  • @evinda I don't think it's necessary at all – Hippalectryon Oct 07 '14 at 16:47
  • But I am asked to prove it by induction! – evinda Oct 07 '14 at 16:47
  • Did you mean $T(n+1)=3T\left (\frac{n}{4} \right)+n$ for $n>1$ instead of $T(n)=3T\left (\frac{n}{4} \right)+n$? (by the way when replying to a specific used, add '@theNameOfTheUser' at the beginning of your post) – Hippalectryon Oct 07 '14 at 16:49
  • @TheGame No, I meant: $$T(n)=3T \left ( \frac{n}{4}\right)+n$$ – evinda Oct 07 '14 at 16:55
  • The information provided in the OP makes it impossible to calculate any value of $T$ other than $T(4^k)$. Perhaps that information is incomplete? – Greg Martin Oct 07 '14 at 17:02
  • Can you assume $n=4^k$ and then use induction on k? – user137481 Oct 07 '14 at 17:08
  • So, can I prove it like that, that $T(n)=O(n)$ ?

    The recursive relation $T(n)=3 T \left ( \frac{n}{n}\right )+n$ is only defined for $n=4^{k},k \geq 0$ , so: $$T(n)=3 T \left ( \frac{n}{4}\right )+n \Rightarrow T(4^k)=3T (4^{k-1})+4^k$$

    $$k=0: n=1: T(1)=1 \leq c \cdot 1 \text{ if } c \geq 1 $$ We suppose that $ T(4^{k-1}) \leq c \cdot 4^{k-1} $.

    $$ T(4^k)=3T(4^{k-1})+4^k \leq c \cdot 4^k \text{ if } c \geq 4 $$

    Could you tell me if it is right?

    – evinda Oct 07 '14 at 20:08
  • $T(4^k)=3^k+3^{k-1}(4^1) +...+ 3(4^k) \le (k+1)4^k=(\frac{log_2(n)}{2}+1)n=O(nlog_2n)$. Then you need to prove that $T(4^{k+1})=O(nlog_2n)$ – user137481 Oct 07 '14 at 20:44
  • How did you get the first equality? – evinda Oct 07 '14 at 20:50
  • I want to prove that the solution I found is right.. So, do I have to prove by induction that $T(n)=4n-3n^{\log_4 3}$ or that $T(n)=O(n)$ ? – evinda Oct 08 '14 at 18:45

1 Answers1

1

By way of enrichment we solve another closely related recurrence that admits an exact solution. Suppose we have $T(0)=0$ and for $n\ge 1$ (this gives $T(1)=1$) $$T(n) = 3 T(\lfloor n/4 \rfloor) + n.$$

Furthermore let the base four representation of $n$ be $$n = \sum_{k=0}^{\lfloor \log_4 n \rfloor} d_k 4^k.$$

Then we can unroll the recurrence to obtain the following exact formula for $n\ge 1$ $$T(n) = \sum_{j=0}^{\lfloor \log_4 n \rfloor} 3^j \sum_{k=j}^{\lfloor \log_4 n \rfloor} d_k 4^{k-j}.$$

Now to get an upper bound consider a string of three digits which yields $$T(n) \le \sum_{j=0}^{\lfloor \log_4 n \rfloor} 3^j \sum_{k=j}^{\lfloor \log_4 n \rfloor} 3 \times 4^{k-j} = 16\times 4^{\lfloor \log_4 n \rfloor} -\frac{27}{2} 3^{\lfloor \log_4 n \rfloor} + \frac{1}{2} .$$

Note that this bound is attained and cannot be improved.

The lower bound is for the case of a one digit followed by a string of zeros and yields $$T(n) \ge \sum_{j=0}^{\lfloor \log_4 n \rfloor} 3^j \times 4^{\lfloor \log_4 n \rfloor-j} = 4\times 4^{\lfloor \log_4 n \rfloor} - 3\times 3^{\lfloor \log_4 n \rfloor}.$$

This bound too is attained.

Joining the dominant terms of the upper and the lower bound we obtain the asymptotics $$4^{\lfloor \log_4 n \rfloor} \in \Theta\left(4^{\log_4 n}\right) = \Theta(n).$$

These are in agreement with what the Master theorem would produce.

Here is another MSE link where some similar computations are carried out.

Marko Riedel
  • 61,317
  • I want to prove that the solution I found is right.. So, do I have to prove by induction that $T(n)=4n-3n^{\log_4 3}$ or that $T(n)=O(n)$ ? – evinda Oct 08 '14 at 18:46
  • You might want to ask your instructor or your TA whether you are allowed to use the exact method that I outlined above. If the answer is yes then an induction proof is not necessary and you just use the two bounds. It might be worthwhile to try to figure out how the exact formula works as this can increase your understanding of these types of problems. To do this write down a small integer in base four and compute the recurrence. – Marko Riedel Oct 08 '14 at 20:30