Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write in java please! 5 . 4 0 The Sieve of Eratosthenes is a method used to compute all primes less than N . Begin

Write in java please!
5.40 The Sieve of Eratosthenes is a method used to compute all primes
less than N. Begin by making a table of integers 2 to N. Find the
smallest integer, i, that is not crossed out. Then print i and cross out i,
2i,3i,dots When i>N2, the algorithm terminates. The running time
has been shown to be O(NloglogN). Write a program to implement
the Sieve and verify the running time claim. How difficult is it to dif-
ferentiate the running time from O(N) and O(NlogN)?
Calculating the actual run time for a given size N
For 5.40 and 5.43 you are asked to verify the run time of algorithms. To do this you need to run your code for varying sizes of N and
plot them. There is a library function which is part of java.lang.System called timeNano() System (Java Platform SE 8)_
(
oracle.com) which returns the current number of nanoseconds expressed a long. Before running your code, store this value. After
running the code, find the difference between the current time and the start time to get the elapsed time. For example
long startTime=System.nanoTime ();
sieveofEratosthenes (1000);
// Express elapsed time in seconds
double elapsedTime=(double)(System. nanoTime ()-startTime)/1E+09;
System.out.printf("Elapsed Time is 8.3f
", elapsedTime);
This gives you one data point for a chart like 5.1 and 5.2. You will need to run several times with varying sizes of N to get enough
points to plot the curve. The step you choose for varying N will depend upon the problem and 5.40 will take quite a few to
distinguish between O(N) straight line and O(NlogN) which curves slightly away from O(N).
Put your entries into an Excel or other spreadsheet to graph the results and turn that in for each problem.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What is American Polity and Governance ?

Answered: 1 week ago

Question

What is the difference between Needs and GAP Analyses?

Answered: 1 week ago

Question

What are ERP suites? Are HCMSs part of ERPs?

Answered: 1 week ago