GATE | GATE-CS-2007 | Question 51

Consider the following C code segment:

int IsPrime(n)
{
  int i,n;
  for(i=2;i<=sqrt(n);i++)
     if(n%i == 0)
      {printf(“Not Prime\n”); return 0;}
  return 1;
}

Let T(n) denotes the number of times the for loop is executed by the program on input n. Which of the following is TRUE?
(A) T(n) = O(sqrt(n)) and T(n) = \Omega(sqrt(n))
(B) T(n) = O(sqrt(n)) and T(n) = \Omega(1)
(C) T(n) = O(n) and T(n) = \Omega(sqrt(n))
(D) None of the above
(A) A
(B) B
(C) C
(D) D


Answer: (B)

Explanation: See Question 5 of http://www.geeksforgeeks.org/data-structures-and-algorithms-set-12/

Quiz of this Question

GATE CS Corner    Company Wise Coding Practice

Recommended Posts:



0 Average Difficulty : 0/5.0
No votes yet.










Writing code in comment? Please use ide.geeksforgeeks.org, generate link and share the link here.