Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lists Samuel Marateck © 2010. The Sieve of Eratosthenes.

Similar presentations


Presentation on theme: "Lists Samuel Marateck © 2010. The Sieve of Eratosthenes."— Presentation transcript:

1 Lists Samuel Marateck © 2010

2 The Sieve of Eratosthenes

3 Place a 0 in all slots X = 26*[0]

4 Place 0’s in all slots. 0000000000000000000000000 12345678910101 1212 1313 1414 1515 1616 1717 1818 1919 2020 21212 2323 2424 2525

5 Start with 2 for j in range(2, √25):

6 Start with 2 for j in range(2, √25): if x[j] == 0:

7 Start with 2 for j in range(2, √25): if x[j] == 0: index = 2*j

8 Start with the 2 slot. 0000000000000000000000000 12345678910101 1212 1313 1414 1515 1616 1717 1818 1919 2020 21212 2323 2424 2525

9 for j in range(2, √25): if x[j] == 0: index = 2*j while index < 25: x[index] = 1

10 Place a 1 in the 4 slot. 0001000000000000000000000 12345678910101 1212 1313 1414 1515 1616 1717 1818 1919 2020 21212 2323 2424 2525

11 for j in range(2, √25): if x[j] == 0: index = 2*j while index < 25: x[index] = 1 index = index + j

12 Then in the 6 slot. 0001010000000000000000000 12345678910101 1212 1313 1414 1515 1616 1717 1818 1919 2020 21212 2323 2424 2525

13 Continue. 0001010100000000000000000 12345678910101 1212 1313 1414 1515 1616 1717 1818 1919 2020 21212 2323 2424 2525

14 0001010101000000000000000 12345678910101 1212 1313 1414 1515 1616 1717 1818 1919 2020 21212 2323 2424 2525

15 0001010101010000000000000 12345678910101 1212 1313 1414 1515 1616 1717 1818 1919 2020 21212 2323 2424 2525

16 Place 1’s in all multiples of 2 slots. 0001010101010101010101010 12345678910101 1212 1313 1414 1515 1616 1717 1818 1919 2020 21212 2323 2424 2525

17 Since there is a 0 in the 3 slot, 3 is prime 0001010101010101010101010 12345678910101 1212 1313 1414 1515 1616 1717 1818 1919 2020 21212 2323 2424 2525

18 There is a 1 already in the 6 slot. 0001010101010101010101010 12345678910101 1212 1313 1414 1515 1616 1717 1818 1919 2020 21212 2323 2424 2525

19 Place a 1 in the 9 slot. 0001010111010101010101010 12345678910101 1212 1313 1414 1515 1616 1717 1818 1919 2020 21212 2323 2424 2525

20 The 12 slot already has a 1. 0001010111010101010101010 12345678910101 1212 1313 1414 1515 1616 1717 1818 1919 2020 21212 2323 2424 2525

21 Then a 1 in the 15 slot. 0001010111010111010101010 12345678910101 1212 1313 1414 1515 1616 1717 1818 1919 2020 21212 2323 2424 2525

22 Then a 1 in the 21 slot. 0001010111010111010111010 12345678910101 1212 1313 1414 1515 1616 1717 1818 1919 2020 21212 2323 2424 2525

23 Now there is a 1 in all multiple of 3 slots. 0001010111010111010111010 12345678910101 1212 1313 1414 1515 1616 1717 1818 1919 2020 21212 2323 2424 2525

24 Skip the 4 slot since it has a 1. 0001010111010111010111010 12345678910101 1212 1313 1414 1515 1616 1717 1818 1919 2020 21212 2323 2424 2525

25 There is a 0 in the 5 slot, so 5 is prime. 0001010111010111010111010 12345678910101 1212 1313 1414 1515 1616 1717 1818 1919 2020 21212 2323 2424 2525

26 Place a 1 in multiple of 5 slots. 0001010111010111010111010 12345678910101 1212 1313 1414 1515 1616 1717 1818 1919 2020 21212 2323 2424 2525

27 The only non-zero slot is 25. 0001010111010111010111011 12345678910101 1212 1313 1414 1515 1616 1717 1818 1919 2020 21212 2323 2424 2525

28 Since √25 is 5 we stop here. 0001010111010111010111011 12345678910101 1212 1313 1414 1515 1616 1717 1818 1919 2020 21212 2323 2424 2525

29 Starting with 2, all the slots with 0’s are prime numbers. 0001010111010111010111011 23571 1313 1717 1919 2323

30


Download ppt "Lists Samuel Marateck © 2010. The Sieve of Eratosthenes."

Similar presentations


Ads by Google