Question: The Algorithm Sieve of Eratosthenes (Java) Here is the algorithm (directions) for the Sieve of Eratosthenes. Let's say we're looking for all the prime number

The Algorithm Sieve of Eratosthenes (Java)

Here is the algorithm (directions) for the Sieve of Eratosthenes. Let's say we're looking for all the prime number that are not bigger than N. (In the pseudocode which follows, we are using explicit names. You do not have to use these names. The use of specific names just makes the pseudocode easier to read.) However, you do have to implement this algorithm for the Sieve. Using a different algorithm for the Sieve will cost you functionality points, a lot of functionality points.

Create a list of all the potential prime numbers (from 2 up to N).

We're including all the numbers between 2 and N because anyone of them might be a prime.

We're excluding one (1) because it's not a prime.

Let's call this list numberList.

Create a list of the prime numbers that we have found.

This list starts out empty.

Let's call this list primeList.

Loop:

Take the lowest (first) number out of numberList. This is a prime number. Let's call it currentPrime.

Add currentPrime to primeList.

Remove all the numbers in numberList that are evenly divisible by currentPrime.

Go back to Loop as long as currentPrime is less than some limit M.

All the rest of the values in numberList are also prime. Move them to primeList.

Rest of the instructions and code here:

http://danjinguji.com/cpts131-f17/work/hw-sieve.html

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!