edited by
746 views
8 votes
8 votes

Consider the following C function.

int func(int n)
{
  int i , j , k , p , q=1;
  for(i=1 ; i<= n ; i++)
  {
    p=0;
    for(k=1 ; k<= n ; k<<=1)
      p++;
    for(j=p ; j>= 1 ; j>>=1);
    q=q<<=1;                    
  }
 return q;
}


Which one of the following is the approximate value returned by the above function?

  1. $\Theta(n)$
  2. $\Theta(2^n)$
  3. $\Theta(2^{(n \log n))}$
  4. $\Theta(\log n)$
edited by

1 Answer

Best answer
8 votes
8 votes
In second inner loop there is semicolon after for loop statement. Hence the value of $q$ will double according to outer loop only i.e $n$ times. So, final value of $q$ becomes $2^n$.

Option B.
selected by
Answer:

Related questions

14 votes
14 votes
1 answer
2