28-section-4

28-section-4 - CS 106A Handout #28 July 21, 2009 Section...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Handout #28 CS 106A July 21, 2009 Section Handout #4—Arrays & Memory Thanks to Eric Roberts for some of these problems, and shouts out to Brandon Burr for some of them too 1. Simple arrays In the third century B.C., the Greek astronomer Eratosthenes developed an algorithm for finding all the prime numbers up to some upper limit N . To apply the algorithm, you start by writing down a list of the integers between 2 and N . For example, if N were 20, you would begin by writing down the following list: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 You then begin by circling the first number in the list, indicating that you have found a prime. You then go through the rest of the list and cross off every multiple of the value you have just circled, since none of those multiples can be prime. Thus, after executing the first step of the algorithm, you will have circled the number 2 and crossed off every multiple of two, as follows: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 From here, you simply repeat the process by circling the first number in the list that is
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/14/2010 for the course CS 106A taught by Professor Sahami,m during the Fall '08 term at Stanford.

Page1 / 3

28-section-4 - CS 106A Handout #28 July 21, 2009 Section...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online