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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started