Posted on

# Build ADT List Application 2 Counting Primes 40 ptsSuppose you are interested in finding prime

Build ADT List Application 2: Counting Primes [40 pts]Suppose you are interested in finding prime numbers between 2 and 15 both inclusive.The algorithm proceeds in rounds. In each round a single prime is discovered fromCandidates list & removed, as also numbers that have that prime as a factor. For this, youwill need to create 3 lists, a Candidates list, a Composites list and a Primes listAssume Candidates list is as follows:Candidates: 2 3 4 5 6 7 8 9 10 11 12 13 14 15Step 1:Go through Candidate list & remove the first prime number found & add to Primes listStep 2:Remove any number(s) in updated Candidates list that is/are divisible by the prime you justremoved and add it to the Composites listStep 3:When no more prime numbers remain in Candidates list, print the three lists To make the operation of the algorithm clearer, copy the contents of the lists as theyappear at the end of the previous round. You can complete the other rounds if you wish,but most of the core work has been completed.Wallthrough of steps for Step 1:(I) Being the first number in the Candidates list, you will start with 2. Since 2 is a primenumber, you will remove 2 from the list of candidates, which makes the list as follows:3 4 5 6 7 8 9 10 11 12 13 14 15(II) Then, in the updated listed above, since 4, 6, 8, 10, 12 and 14 are all divisible by 2, youwill need to remove each of these from the list of candidates one at a time, and add themto Composites list.After the above 2 steps, your Candidates, Composites and Primes lists will look as follows:Candidates: 3 5 7 9 11 13 15Primes: 2Composites: 4 6 8 10 12(III) Repeat steps I and II above using the updated Candidates list and continue to updatethe Primes and Composites list until no more prime numbers are left in the Candidates list(IV) The three lists in their respective final states should be printed by the application

Solved By Verified
Study Co-Pilot

Instant