in Algorithms edited by
17,792 views
47 votes
47 votes

Consider the recurrence function

$$T(n) = \begin{cases} 2T(\sqrt{n})+1, & n>2 \\ 2, & 0 < n \leq 2 \end{cases}$$

Then $T(n)$ in terms of $\Theta$ notation is

  1. $\Theta(\log \log n)$
  2. $\Theta( \log n)$
  3. $\Theta (\sqrt{n})$
  4. $\Theta(n)$
in Algorithms edited by
by
17.8k views

2 Comments

edited by
alternate method

n=0,1   T(0),T(1)=2

n=2   T(2)=2

now  T(4)=2*(T(2)+1 =5

       T(16)=2*5+1=11

       T(256)=2*11+1=23

       T(2^16) =2*23+1=47

       T(2^32)=2*47+1=95

      Log(2^32)=32 which lower bounds  95  so ans can  can;t be c or d   option a gives 5 which also lower bound 95  but as it is theta notation we go for tight bound
4
4
Hey plz help me why option b not option a .in the case of 2^32 valise from option 1 is theta(5) which can also be upper bounded by 95 as you said in your statement ?
0
0

6 Answers

69 votes
69 votes
Best answer

$T(n)=2T({\sqrt{n}})+1$

Put, $n=2^m$ which implies $\sqrt n = n^{1/2} =2^{m/2}$

$\implies T(2^m)=2T(2^{m/2})+1$

put, $T(2^m) =S(m)$ which implies $T(2^{m/2}) = S(m/2)$

$\implies S(m)=2S(m/2)+1$

Using case 1 of master method ,

$=\Theta(m) = \Theta(\log n)$

 https://gateoverflow.in/1829/gate2006-51-isro2016-34?show=37791#c37791

Correct Answer: $B$

edited by

4 Comments

same concept ques was there in 2007, in that ques ans. was LogLog(n), Rzn: we are cutting the exponent of input by half.

DOUBT: WHY WE ARE CONSIDERING Log(n) HERE?

0
0
how do we know to put n= 2^k
0
0

@MadhavBansal It is intuitive like this:-

Suppose, $T(n) = aT(\sqrt[b]{n})+f(n)$ where $a>=1, b>1$

So, assume $[n=b^m → \sqrt[b]{n} = b^{m/b}]$

Thus, $T(b^m) = aT(b^{m/b}) + g(m)$

Then, assume $T(b^m) = S(m) → T(b^{m/b}) = S(m/b)$

So, $S(m) = aS(m/b) + g(m)$  // Apply Master Theorem now

1
1
34 votes
34 votes

Though $\sqrt{n}=2^m$ is the shortest method.

$T(n)=2T(n^{1/2}) +1$

$=2 *[ 2 T((n^{1/2})^{1/2}) +1] +1$

$=2^{2} T((n^{1/4}) +2 +1$

$=2^{3} T((n^{1/2^{3}}) +4 +2 +1$

$=2^{k} T((n^{1/2^{k}}) +2^{k-1}+ 2^{k-2}+..............+4 +2 +1$

$=2^{k} T((n^{1/2^{k}}) +[(2^{k}-1)/ 2-1] * 2^{0}$


as per given termination condition is $n^{1/2^{k}} =2$

$\Rightarrow log(n^{1/2^{k}}) =log(2)$

$\Rightarrow log(n) =2^{k}$

$\Rightarrow log( log(n)) =k$


inserting value of k or 2^k in above equation

$T(n)= log(n) * T(2) + log(n) - 1$

$T(n)= 3 log(n) - 1$


$T(n)= \Theta (log(n))$

Answer is B

by

3 Comments

inserting value of k or 2^k in above equation

T(n)=log(n)∗T(2)+log(n)−1

can you please explain this.

0
0

how we get this particular equation.

T(n)=log(n)∗T(2)+log(n)−1

0
0

this is the best explanation I found on youtube:: 

0
0
26 votes
26 votes

Hence answer is b.

13 votes
13 votes

hope it might help....

1 comment

Thanku Dude
1
1
Answer:

Related questions