Question: Algorithm to generate all the primes up to given bound n . It uses an array . n , and runs as follows: for k

Algorithm to generate all the primes up to given bound n. It uses an array .
n, and runs as follows:
for k=2 to n do A[k]-1
for k=2 to n2 do
if A[k]=1 then
i=2k
while in do
A[i]=0,i=i+k
Exercise 1
One drawback of the above algorithm is its use of space: it requires an array of size n.
Show how to modify the algorithm, without substantially increasing its running time,
so that one can enumerate all the primes up to n, using an auxiliary array of size just
O(n2)
 Algorithm to generate all the primes up to given bound 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!