1 / 4

Sorting algorithms Sieve of Eratosthenes

Sorting algorithms Sieve of Eratosthenes. Dr. Szczepan Paszkiel Department of Electrical, Control & Computer Engineering Institute of Control & Computer Engineering Opole University of Technology. Sieve of Eratosthenes - pseudocode. Input : an integer n > 1

lida
Download Presentation

Sorting algorithms Sieve of Eratosthenes

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Sorting algorithms Sieve of Eratosthenes Dr. Szczepan Paszkiel Department of Electrical, Control & Computer Engineering Institute of Control & Computer Engineering Opole University of Technology

  2. Sieve of Eratosthenes - pseudocode Input: an integer n > 1 Let A be an array of Boolean values, indexed by integers 2 to n, initially all set to true. fori = 2, 3, 4, ..., √n : ifA[i] is true: forj = i2, i2+i, i2+2i, ..., n: A[j] := false Now all i such that A[i] is true are prime.

  3. Sieve of Eratosthenes flowchart YES NO a[i] = true  - prime number a[i] = false - composite number NO YES

  4. Sieve of Eratosthenes in C++ for(int i = 2; i <= N; i++) a[i] = 1; max = (int)sqrt(N); for(i = 2; i <= max; i++) if(a[i]==1) { j = i + i; while(j <= N) { a[j] = 0; j += i; } }

More Related