Menu

Right Java Code Following Pseudo Code Use Pseudo Code Online Give Likes Explanation Q43804000

Right JAVA code for the following pseudo code. Use only thispseudo code Not other, from online, will give likes!
ALGORITHM Sieve(n) //Implements the sieve of Eratosthenes //Input: A positive integer n > 1 //Output: Array L of all prime nu

explanation below

program implementing this procedure. Incidentally, Step 3 is also not defined clearly enough. Its ambiguity is much easier to

What is the largest number p whose multiples can still remain on the list to make further iterations of the algorithm necessa

ALGORITHM Sieve(n) //Implements the sieve of Eratosthenes //Input: A positive integer n > 1 //Output: Array L of all prime numbers less than or equal to n 1.1 What Is an Algorithm? for p + 2 to n do A[p] + p. for p + 2 to n do Ilsee note before pseudocode if A[p]+ 0 llp hasn’t been eliminated on previous passes ja p * while j < n do A[j]0 /mark element as eliminated joj +p l/copy the remaining elements of A to array L of the primes ino for p + 2 to n do if A[p]#0 L[i] + A[p] iri+1 return L program implementing this procedure. Incidentally, Step 3 is also not defined clearly enough. Its ambiguity is much easier to rectify than that of the factorization steps, however. How would you find common elements in two sorted lists? So, let us introduce a simple algorithm for generating consecutive primes not exceeding any given integer n > 1. It was probably invented in ancient Greece and is known as the sieve of Eratosthenes (ca. 200 B.C.). The algorithm starts by initializing a list of prime candidates with consecutive integers from 2 to n. Then, on its first iteration, the algorithm eliminates from the list all multiples of 2, i.e., 4, 6, and so on. Then it moves to the next item on the list, which is 3, and eliminates its multiples. (In this straightforward version, there is an overhead because some numbers, such as 6, are eliminated more than once.) No pass for number 4 is needed: since 4 itself and all its multiples are also multiples of 2, they were already eliminated on a previous pass. The next remaining number on the list, which is used on the third pass, is 5. The algorithm continues in this fashion until no more numbers can be eliminated from the list. The remaining integers of the list are the primes needed. As an example, consider the application of the algorithm to finding the list of primes not exceeding n= 25: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 2 3 5 7 9 11 13 15 17 19 21 23 25 2 3 5 7 11 13 17 19 2 3 5 7 11 13 17 19 What is the largest number p whose multiples can still remain on the list to make further iterations of the algorithm necessary? Before we answer this question, let us first note that if p is a number whose multiples are being eliminated on the current pass, then the first multiple we should consider is p·p because all its smaller multiples 2p, …, (p – 1)p have been eliminated on earlier passes through the list. This observation helps to avoid eliminating the same number more than once. Obviously, p. p should not be greater than n, and therefore p cannot exceed Vn rounded down (denoted | Vn using the so-called floor function). We assume in the following pseudocode that there is a function available for computing Vn; alternatively, we could check the inequality p:p <n as the loop continuation condition there. ALGORITHM Sieve(n) //Implements the sieve of Eratosthenes //Input: A positive integer n > 1 //Output: Array L of all prime numbers less than or equal to n Show transcribed image text ALGORITHM Sieve(n) //Implements the sieve of Eratosthenes //Input: A positive integer n > 1 //Output: Array L of all prime numbers less than or equal to n 1.1 What Is an Algorithm? for p + 2 to n do A[p] + p. for p + 2 to n do Ilsee note before pseudocode if A[p]+ 0 llp hasn’t been eliminated on previous passes ja p * while j 1. It was probably invented in ancient Greece and is known as the sieve of Eratosthenes (ca. 200 B.C.). The algorithm starts by initializing a list of prime candidates with consecutive integers from 2 to n. Then, on its first iteration, the algorithm eliminates from the list all multiples of 2, i.e., 4, 6, and so on. Then it moves to the next item on the list, which is 3, and eliminates its multiples. (In this straightforward version, there is an overhead because some numbers, such as 6, are eliminated more than once.) No pass for number 4 is needed: since 4 itself and all its multiples are also multiples of 2, they were already eliminated on a previous pass. The next remaining number on the list, which is used on the third pass, is 5. The algorithm continues in this fashion until no more numbers can be eliminated from the list. The remaining integers of the list are the primes needed. As an example, consider the application of the algorithm to finding the list of primes not exceeding n= 25: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 2 3 5 7 9 11 13 15 17 19 21 23 25 2 3 5 7 11 13 17 19 2 3 5 7 11 13 17 19
What is the largest number p whose multiples can still remain on the list to make further iterations of the algorithm necessary? Before we answer this question, let us first note that if p is a number whose multiples are being eliminated on the current pass, then the first multiple we should consider is p·p because all its smaller multiples 2p, …, (p – 1)p have been eliminated on earlier passes through the list. This observation helps to avoid eliminating the same number more than once. Obviously, p. p should not be greater than n, and therefore p cannot exceed Vn rounded down (denoted | Vn using the so-called floor function). We assume in the following pseudocode that there is a function available for computing Vn; alternatively, we could check the inequality p:p 1 //Output: Array L of all prime numbers less than or equal to n

Expert Answer


Answer to Right JAVA code for the following pseudo code. Use only this pseudo code Not other, from online, will give likes! explan…

OR