Prove that the time complexity for the following code is nloglogn. void sieveOfEratosthenes(int n){ boolean prime[] = new boolean[n+1]; for(int i=0;i


Prove that the time complexity for the following code is nloglogn.


void sieveOfEratosthenes(int n){
      boolean prime[] = new boolean[n+1];
      for(int i=0;i<>
           prime[i] = true;
     for(int p = 2; p<=sqrt(n);>
          // If prime[p] is not changed, then it is a prime//


          if(prime[p] == true){
               // Update all multiples of p
              for(int i = p*p; i <= n;="" i="" +="">
              prime[i] = false;


              }
        }
      // Print all prime numbers
       for(int i = 2; i <= n;="">
           if(prime[i] == true)
           System.out.print(i + " ");


       }


}



Jun 05, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here