Question: Just need the steps followed to change the following code. Thanks 256 CHAPTER9 ARRAYS The above code can be modified to make it faster and
256 CHAPTER9 ARRAYS The above code can be modified to make it faster and save space. that. Your task is to do The first for loop that sets the values of isPrime to true wastes it to set isPrime [P) to true only for p - 2 and for all odd p >1. T Change care of even numbers: we know that the onty even prime is 2. Since we have taken care of even numbers, start the second for I and change the step from I to 2 ue wastes time. any1. This takes I. 3. Given the changes made in the previous two items, can the step in the (inner) for loop be increased? How? third 4. Note that when we get to p, the numbers 2p, 3p,.., (p)p will already have ben crossed out on previous iterations. Make a change to the inner for loon utilize that fact to make the code a little faster. 5. We know that no even number except 2 is prime. To save space used to store rs are represented in the numbers, change the Sieve code so that only odd numbe is Prime array: s Prime [k] s set to true if and only if 2k+1 s prime. indow Help 1 V/ Sieve of Ecatosthenes 3 public class Sieve sprine[p] is set to true if and only if p is a prime 7e public static boolean[] markPrines(int n) boolean[] sPrine-new boolean[n]; // all set to false by default sPrine. sPrine[1)-false; // optional for (int 2;
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
