Google Answers Logo
View Question
 
Q: sieve of eratosthenes flow chart ( Answered 4 out of 5 stars,   0 Comments )
Question  
Subject: sieve of eratosthenes flow chart
Category: Reference, Education and News
Asked by: briguy8971-ga
List Price: $10.00
Posted: 12 Apr 2004 20:13 PDT
Expires: 12 May 2004 20:13 PDT
Question ID: 329284
i need a flow chart and or formulas to fill into my flow chart for a
sieve of erathosthenes flow chart
Answer  
Subject: Re: sieve of eratosthenes flow chart
Answered By: livioflores-ga on 13 Apr 2004 00:26 PDT
Rated:4 out of 5 stars
 
Hi briguy8971!!


Here is what i found to help you. If it is not suffice, please let me
know and I will continue researching.


"The Sieve of Eratosthenes":
"Eratosthenes devised a 'sieve' to identify prime numbers. A sieve is
like a strainer that you drain spaghetti through when it is done
cooking.  The water drains out, leaving your spaghetti behind. The
Sieve of Eratosthenes drains out composite numbers and leaves prime
numbers behind:
- Make a list of all the integers less than or equal to n (and greater than one). 
- Strike out the multiples of all primes less than or equal to the
square root of n.
- Then the numbers that are left are the primes."
This page shows an algorith written in pseudo-code.
http://primes.utm.edu/glossary/page.php?sort=SieveOfEratosthenes


Here you will find some algorithms:

"Sieve of Eratosthenes"
Here you will find an explanation about how to write a Sieve of
Eratosthenes algorithm.
http://rvcc2.raritanval.edu/~tsiefrin/c-labs-sieve.htm

"QBasic - Sieve of Eratosthenes":
This algorithm finds all the primes up to some bound by implementing
the sieve of Eratosthenes.
http://www.math.umbc.edu/~campbell/NumbThy/Class/Programming/QBASIC/PRIMSIEV.BAS

"Sieve of Eratosthenes Benchmark":
At the 'Source Code' you will find links to algorithms written in
different programming languages.
http://www.bagley.org/~doug/shootout/bench/sieve/

Here is the one that I recommend to do a flowchart (note that the
QBasic one is another good choice):
"Sieve of Eratosthenes"
http://www.roguewave.com/support/docs/sourcepro/stdlibug/5-4.html

--------------------------------------------------------- 

Here is a "translation" of the algorithm that makes you easy the
construction of the flowchart (please test it!!):

- Input the number N (the size of the sieve)
  
    N

- Create an array of ints, initially set all to 1.
   
    a[x] = 1 for all x from 1 to N.

- Starting at i = 2, at positions that are multiples of i, set value to zero.
  
      i = 2
     (Main loop) 
     WHILE  (i*i =< N)
          DO

            (Second loop)
            IF a[i] = 1
              THEN
                  j = i + i

                  (Third loop)
                  WHILE j =< N
                       DO 
                         a[j] = 0
                         j = j + i
                  End of WHILE (End of 3rd loop)

            End of IF (End of 2nd loop)

            i = i + 1
      End of WHILE (End of main loop)

- Now output all the values that are still set.
     j = 2 
     WHILE j =< N
          DO
            IF a[j] = 1 
              THEN
                  PRINT j    
            End of IF     
          j = j + 1
     End of WHILE  

     END of PROGRAM.
 
----------------------------------------------------------

Another "Sieve of Eratosthenes" algorithm:
http://www.comp.dit.ie/rlawlor/Prob_Solv/Imperative_Algs/Sieve%20of%20Eratosthenes.pdf


Finally a list of resources that will help you to do flowcharts:

"Designing programs with flow charts"
http://users.evtek.fi/~jaanah/IntroC/DBeech/3gl_flow.htm

"Programming Tools"
http://acweb.colum.edu/users/rcourington/Progclass/week2.html


More advanced references:

"Arrays and Bounded Iteration" from the School of Informatics,
University of Edinburgh:
See sections 16.3 and 16.4 
http://www.inf.ed.ac.uk/teaching/classes/cs1/03-04/Ah/Notes/JavaArrays.pdf

"Loops" from the School of Computer Science at the University of Birmingham:
http://www.cs.bham.ac.uk/~udr/Intro/2001/handouts/handout07.pdf

"Introduction to Arrays" from University of Cincinnati:
http://homepages.uc.edu/~eshomtl/it171/Class7.ppt


Search strategy:
sieve of eratosthenes flowchart
"sieve of eratosthenes" algorithm
flowchart programming sample
flowchart programming sample array


I hope this helps. Please note that the algorithm "translation" have
minor chages from the original, the intention of this changes is to
adapt the algorithm for an easy flowchart, this changes can result in
an erroneous algorithm, so I strongly suggest you to test it and
improve it if it is necessary. It will be better if you can do the
flowchart from the original algorithm.
Feel free to request for any clarification needed.

Best regards.
livioflores-ga
briguy8971-ga rated this answer:4 out of 5 stars
thanks this was very helpfull

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy