retagged by
896 views

2 Answers

Best answer
2 votes
2 votes

T(n)=T(n1/2) + O(1)

T(1)= O(1)

Let n=2k

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

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

Using masters theorem,

T(k)=O(logk)

since n=2k

k=logn

logk=loglogn

Hence T(n)=O(loglogn)

selected by
0 votes
0 votes

The Recurrence Relation from the function we get is:

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

$C$: constant time so say ‘$1$’

then,

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

Now,

Lets Assume $n = 2^{t}$,

Therefore, 

$n^{1/2}$ $=$  $2^{t/2}$

Therefore the equation becomes,

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

Now, Say there is a function $P(t)$ such that $P(t) = T(2^{t}),$            $….(i)$

So the equation becomes,

$P(t) = P(t/2) + 1$

Now, 

Using masters theorem,

$P(t)=\Theta (\log_{2}t)$

and $P(t) = T(2^{t}) = T(n)$            $from(i)$

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

Now,
$\because  n = 2^{t},$

$ \therefore  t=\log_{2}n$

$ \therefore  log_{2}t=\log_{2}\log_{2}n$

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

 

 

Related questions

1 votes
1 votes
2 answers
2
Pranav Madhani asked May 26, 2017
1,905 views
int f(int n) { static int i = 1; if (n ≥ 5) return n; n = n + i; i++; return f(n); }The value returned by f(1) is:(a) 5 (b) 6(c) 7 (d) 8 need solution with explaination...