search
Log In
44 votes
12.2k views

Consider the following recurrence:

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

Which one of the following is true?

  1. $ T(n)=\Theta (\log\log n)$
  2. $ T(n)=\Theta (\log n)$
  3. $ T(n)=\Theta (\sqrt{n})$
  4. $ T(n)=\Theta (n)$
in Algorithms
edited by
12.2k views
6
Using some substitutions along with applying master theorem answer seems to be O(logn). But i have a doubt. For n=2 ceil(sqrt(2)) will be 2 always. Since this will never converge, recurrence wont terminate. Any ideas what should be done here.
4
You are correct. It should be a mistake in question. Case 2 should have been specially mentioned.
0
hello, can you give the brief idea what's going in this recurrence ?
1
B. $\log n$
1
I am not clear what you are trying to say
2

If someone is getting confused in the  S(m) = 2S(m / 2) + 1  line in jatin's comment below,

then pls see below explanation,

T(2m) = 2T(2m/2) + 1

=>Let , T(2m) = S(m)

=> 2T(2m / 22) + 1

=> 2S(m / 2) + 1 (2m == m & 22 == 2)

 

 

 

 

0

Thanks man , I got the point now.

Feeling a bit bad coz , it wasn't that hard but It's just how well u understood  THE SUBSTITUTION USED IN THE method.

3

 

Is this correct?

0
Correct!

8 Answers

47 votes
 
Best answer

$T(n) = 2T\left(n^{\frac{1}{2}}\right)+1$

           $ = 2\left(2T\left(n^{\frac{1}{2^2}}\right) + 1\right) + 1 $

           $ = 4\times T\left(n^{\frac{1}{2^2}}\right) + 5 $

           $ = 8\times T\left(n^{\frac{1}{2^3}}\right) + 13 \\ \cdots$

           $=2^{(\lg \lg n)} + 2 \times \lg \lg n  + 1\text{ (Proved below)} $

           $= \Theta(\lg n)$


$n^{\frac{1}{2^k}} = 2 \\ \text{(Putting 2 so that we can take log.}\\\text{One more step of recurrence can't change the complexity.)} \\\implies \frac{1}{{2^k}} \lg n = 1 \text{(Taking log both sides)}\\\implies \lg n = 2^k \\\implies k = \lg \lg n$

So, answer is B, $T(n) = \Theta(\log n)$


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

Put, $n=2^m$

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

put,$T(2^m) =s(m)$

$s(m)=2s(m/2)+1$

Using case 1 of master method ,

$=\Theta(m) = \Theta(\log n)$
0
@asu what is correct answer here ?
3
it is B, both methods are fine - it was marked wrongly as A.
10
$\begin{align*} \\ T(n) & =2T(\sqrt{n}) +1 \\ & =2T(n^{\frac{1}{2}})+1 \\ & = 4T(n^{\frac{1}{4}})+3 \\ & = 8T(n^{\frac{1}{8}})+ 7 \\ & = 2^{k} T(n^{\frac{1}{2^{k}}})+ (2^{k} -1 ) \end{align*}$

When we put  $k= \log \log n$

$2^{\log \log n}T(2)+2^{\log \log n} -1$
How this is $\Theta( \log n )$  ?
1
@Arjun sir
I think u have missed 2 in the first step pls check that
0
Thanks. Corrected..
9
@Dulqar since $\alpha^{log_{\alpha}x} = x$, we get $2^{log_{2}log_{2}n} + T(2) + 2^{log_{2}log_{2}n}-1= log_2n + T(2) + log_2n - 1$

Constants are ignored, and we are left with $log_2n$.
1
But in Official Key of ISRO, answer is Option A
2

I'm getting same answer- option (b), but my second last step is different. Please someone guide me where am I getting wrong?

0
@jatin_saini, are you sure, according to your method  i am getting O(n), can you show your procedure once ..!
1
here que case 2 ie,T(1)=1 is given as wrong so T(2)=1 is correctone, now you could get the ans
1
How you got O(n).

You can check procedure above.
1

How to get that m/2 after substituting T(2m) =  S(m)

0
i get Θ(n) then how you got log n using master theoram step 1. plz explain this i am confusing only last step.
0

I am not getting the second last step of the solution , how T(n ^ (1/2^k)) becomes equal to T(1) as it will be possible only when T(1)=2, but it is given in question that T(1)=1.

3

@dharmesh7

T(n)=2T(√ n )+1   

Put, n=2^m

T(2^m)=2T(2^m/2)+1

put,T(2^m)=s(m)

s(m)=2s(m/2)+1

Using case 1 of master method ,

=Θ(m) 

because of ,

 n = 2^m (take log both of the side )

logn = m log2

m = log n 
so
=Θ(logn)

0
thanks
1
Can anyone please tell regarding Jatin solution, what is the approach and how to think to substitute n = $2^{m}$
1
What does T(2^m)=S(m) mean? Why cant it be T(2^m)=T(p) by putting 2^m=p ?
2
$T(2^m)$ and  $S(m)$  are just functions...

$T(2^m)$  is function of m, replaced by $S(m)$

$T(2^{m/2})$  is a function of $m/2$ , which is replaced by  $S(m/2)$.
0
I am having difficulty to understand how such substitution works.Can you please elaborate it?
Also,Is there any other way to do it?
0
You can do it as it is done in selected answer
11 votes
$T(n)=2T(\sqrt{n})+1$

          $ =2T(2m)+1$    $n=2^{m}$ , $m=log n$

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

           $ =O(m)$

           $=O(log n)$

edited by
1
√n=2^m then m=log n

Logic is not clear.
0
see jatin saini's answer. He applied correct logic.

srestha , your answer is correct but i doubt if procedure and logic correct too...
1

@srestha 

It should be  $n=2^m$,  not $\sqrt n=2^m$

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

Put, $n=2^m$

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

$T(log2^m)=2T(log2^{m/2})+c$

$T(m)=2T(m/2)+c$

Using case 1 of master theorem,

$=\Theta(m)$

SInce, $n=2^m$

$= \Theta(\log n)$

edited by
5 votes

asume n=2k and k=log n

T(2k)=T(2k/2)+1

asume T(2)=S(k)

now S(k)=s(k/2)+1

use master theorm a=1 andb=2

T(2k)=logk

T(n)=log log(n)

0

It is not right solution,bcoz 2 is miss in the equation.

Right equation is , S(k)= 2s(k/2)+1

By Master theorem  ,S(k)= k

then T(n)= logn

Hence ans is B) logn

4 votes

Unrolling the recursion,

T(n)  =  2T(n^(1/2)) + 1
=  2^2T(n^(1/4)) + 2
= 2^3T(n^(1/8)) + 3
.
.    k  steps
.
=  2^kT(n^(1/2k)) + k              …………. (1)

Using the Base case,

n^(1/2k) = 2
Taking log on both sides
log2n = 2k
k = log2log2n

From (1),

T(n) =  log2n  +  log2log2n
= Theta(log2n)

Here log2n : log(base 2) n

1 vote

$Ans:B$


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

Assume $n=2^k$

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

Assume $T(2^k)=S(k)$

$S(k)=2S(k/2)+1$

Apply Master Theorem

$S(k)=\Theta(k)$

Now just do the reverse

$T(2^k)=\Theta(k)$

Now replace with $k=log_{2}n$

$T(2^{log_{2}n})=\Theta(log_{2}n)$

$T(n)=\Theta(log_{2}n)$

 

0 votes

Hope this helps :)

0 votes
we can do this question by one more way.

T(n)=2T(⌈√n⌉)+1T(1)=1

 

Here, if a recursion program would be formed from this relation then, returning statement would be

return √n+√n +c( any other constant) which becomes 2T(√n) + c

for example, if we take n=8 then √8=2√2 whose ceiling value is 3 and ceiling value is also mentioned in the question.

and log8 base 2 =3

therefore  Θ(log n)
Answer:

Related questions

33 votes
1 answer
1
12.2k views
A CPU generates $32$-bit virtual addresses. The page size is $4$ KB. The processor has a translation look-aside buffer (TLB) which can hold a total of $128$ page table entries and is $4$-way set associative. The minimum size of the TLB tag is: $\text{11 bits}$ $\text{13 bits}$ $\text{15 bits}$ $\text{20 bits}$
asked Sep 26, 2014 in Operating System Rucha Shelke 12.2k views
45 votes
4 answers
2
11.7k views
Consider the following statements about the context free grammar $G = \left \{ S \rightarrow SS, S \rightarrow ab, S \rightarrow ba, S \rightarrow \epsilon \right \} $ $G$ is ambiguous $G$ produces all strings with equal number of $a$'s and $b$'s $G$ can ... deterministic PDA. Which combination below expresses all the true statements about $G$? I only I and III only II and III only I, II and III
asked Sep 18, 2014 in Compiler Design Rucha Shelke 11.7k views
14 votes
2 answers
3
5.3k views
For the real time operating system, which of the following is the most suitable scheduling scheme? Round robin First come first serve Pre-emptive Random scheduling
asked Jul 6, 2016 in Operating System jothee 5.3k views
42 votes
15 answers
4
13k views
Consider the following segment of C-code: int j, n; j = 1; while (j <= n) j = j * 2; The number of comparisons made in the execution of the loop for any $n > 0$ is: $\lceil \log_2n \rceil +1$ $n$ $\lceil \log_2n \rceil$ $\lfloor \log_2n \rfloor +1$
asked Jul 6, 2016 in Algorithms Arjun 13k views
...