Question: Implement the following algorithm in Python with a function called sieve_of_eratosthenes ( n ), where n is an integer value, which returns all prime numbers

 Implement the following algorithm in Python with a function called sieve_of_eratosthenes

Implement the following algorithm in Python with a function called sieve_of_eratosthenes ( n ), where n is an integer value, which returns all prime numbers up to n. For example, >>> sieve_of_eratosthenes ( 30 ) [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] See the following page for more: https://en.wikipedia.org/wiki/Sieve of Eratosthenes ALGORITHM Sieve_of_Eratosthenes ( n ): INPUT: An integer n > 1 OUTPUT: All prime numbers [2 .. n] LET A be an array of boolean values, indexed by integers [2 .. n] initially all set to True. FOR i = 2, 3, 4, ..., not exceeding Vn DO if A[i] is True: FOR j = i^2, i^2+i, i^2+2i, i^2+3i, ..., not exceeding n DO # Mark all numbers that are not prime numbers A[j] = False RETURN all i for which A[i] is True

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!