edited by
869 views
2 votes
2 votes

Consider the following C code segment:

int Ls Prime(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)$ denote the number of times the for loop is executed by the program on input $n.$ Which of the following is true?

  1. $T(n) = O(\sqrt{n})$ and $T(n) = \Omega (\sqrt{n})$
  2. $T(n) = O(\sqrt{n})$ and $T(n) = \Omega (1)$
  3. $T(n) = O(n)$ and $T(n) = \Omega (\sqrt{n})$
  4. None of these
edited by

3 Answers

1 votes
1 votes
option b

in best case  if cond satisfy 1 time and return  

 

in wrost case  root(n)  time loop will itetrate
0 votes
0 votes
Option B) is the answer , Best case complexity –  O(1)

                                        Worst case complexity – O(n^1/2)
Answer:

Related questions

1 votes
1 votes
3 answers
1
admin asked Apr 1, 2020
1,018 views
An algorithm is made up of two modules $M1$ and $M2.$ If order of $M1$ is $f(n)$ and $M2$ is $g(n)$ then he order of algorithm is$max(f(n),g(n))$$min(f(n),g(n))$$f(n) + g...
1 votes
1 votes
1 answer
2
0 votes
0 votes
2 answers
3
admin asked Apr 1, 2020
1,036 views
Which of the following algorithm solve the all-pair shortest path problem?Dijakstra’s algorithmFloyd’s algorithmPrim’s algorithmWarshall’s algorithm
0 votes
0 votes
1 answer
4