The Gateway to Computer Science Excellence

First time here? Checkout the FAQ!

x

+30 votes

Consider the following recurrence:

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

Which one of the following is true?

- $ T(n)=\Theta (\log\log n)$
- $ T(n)=\Theta (\log n)$
- $ T(n)=\Theta (\sqrt{n})$
- $ T(n)=\Theta (n)$

+34 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)$

+78

$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)$

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)$

+4

$\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 )$ ?

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

$2^{\log \log n}T(2)+2^{\log \log n} -1$

How this is $\Theta( \log n )$ ?

+4

@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$.

Constants are ignored, and we are left with $log_2n$.

+1

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

+8 votes

+6 votes

asume n=2^{k} and k=log n

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

asume T(2^{k })=S(k)

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

use master theorm a=1 andb=2

T(2^{k})=logk

T(n)=log log(n)

+2 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**

- All categories
- General Aptitude 1.4k
- Engineering Mathematics 6k
- Digital Logic 2.3k
- Programming & DS 4.3k
- Algorithms 3.7k
- Theory of Computation 4.7k
- Compiler Design 1.7k
- Databases 3.4k
- CO & Architecture 2.9k
- Computer Networks 3.4k
- Non GATE 1.2k
- Others 1.3k
- Admissions 506
- Exam Queries 482
- Tier 1 Placement Questions 22
- Job Queries 64
- Projects 16

40,992 questions

47,619 answers

146,891 comments

62,346 users