Question: Right JAVA code for the following pseudo code. Use only this pseudo code Not other, from online, will give likes! explanation below ALGORITHM Sieve(n) //Implements

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

explanation below

code Not other, from online, will give likes! explanation below ALGORITHM Sieve(n)

//Implements the sieve of Eratosthenes //Input: A positive integer n > 1

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 pp 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

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!