Assignment 1 Andy Wang COP 4530: Data Structures, Algorithms, and Generic Programming.
-
Upload
junior-preston -
Category
Documents
-
view
215 -
download
1
Transcript of Assignment 1 Andy Wang COP 4530: Data Structures, Algorithms, and Generic Programming.
![Page 1: Assignment 1 Andy Wang COP 4530: Data Structures, Algorithms, and Generic Programming.](https://reader038.fdocuments.in/reader038/viewer/2022110103/5697bf871a28abf838c88a17/html5/thumbnails/1.jpg)
Assignment 1
Andy WangCOP 4530: Data Structures,
Algorithms, and Generic Programming
![Page 2: Assignment 1 Andy Wang COP 4530: Data Structures, Algorithms, and Generic Programming.](https://reader038.fdocuments.in/reader038/viewer/2022110103/5697bf871a28abf838c88a17/html5/thumbnails/2.jpg)
Scope of Assignment 1 Class implementation BitVector implementation BitVector application Multi-file compilation Library compilation
![Page 3: Assignment 1 Andy Wang COP 4530: Data Structures, Algorithms, and Generic Programming.](https://reader038.fdocuments.in/reader038/viewer/2022110103/5697bf871a28abf838c88a17/html5/thumbnails/3.jpg)
Deliverables sieve.h, sieve.cpp, bitvector.cpp, main.cpp
Makefile Hardcopy of development log
Daily journal Features implemented, bugs fixed, help
obtained from other people Due in class on Sept 15
![Page 4: Assignment 1 Andy Wang COP 4530: Data Structures, Algorithms, and Generic Programming.](https://reader038.fdocuments.in/reader038/viewer/2022110103/5697bf871a28abf838c88a17/html5/thumbnails/4.jpg)
Sieve Algorithm Find all prime numbers <= n Observation
If n is not prime It is divisible by a prime number <=
sqrt(n)
![Page 5: Assignment 1 Andy Wang COP 4530: Data Structures, Algorithms, and Generic Programming.](https://reader038.fdocuments.in/reader038/viewer/2022110103/5697bf871a28abf838c88a17/html5/thumbnails/5.jpg)
Sieve Algorithm Example: Sieve 9
1. Create a bit vector b of 10 elements0 0 0 0 0 0 0 0 0 0
2. Set all bits of b 1 1 1 1 1 1 1 1 1 1
3. Unset b[0] and b[1], since the smaller prime number is 2 0 0 1 1 1 1 1 1 1 1
![Page 6: Assignment 1 Andy Wang COP 4530: Data Structures, Algorithms, and Generic Programming.](https://reader038.fdocuments.in/reader038/viewer/2022110103/5697bf871a28abf838c88a17/html5/thumbnails/6.jpg)
Sieve Algorithm
4. for (k = 2; k <= sqrt(10); ++k)
0 1 2 3 4 5 6 7 8 90 0 1 1 1 1 1 1 1 1
k
![Page 7: Assignment 1 Andy Wang COP 4530: Data Structures, Algorithms, and Generic Programming.](https://reader038.fdocuments.in/reader038/viewer/2022110103/5697bf871a28abf838c88a17/html5/thumbnails/7.jpg)
Sieve Algorithm
4. for (k = 2; k <= sqrt(10); ++k)for (j = 2*k; j <= 10; j +=
k)
0 1 2 3 4 5 6 7 8 90 0 1 1 1 1 1 1 1 1
k j
![Page 8: Assignment 1 Andy Wang COP 4530: Data Structures, Algorithms, and Generic Programming.](https://reader038.fdocuments.in/reader038/viewer/2022110103/5697bf871a28abf838c88a17/html5/thumbnails/8.jpg)
Sieve Algorithm
4. for (k = 2; k <= sqrt(10); ++k)for (j = 2*k; j <= 10; j +=
k)
Unset b[j];
0 1 2 3 4 5 6 7 8 90 0 1 1 0 1 1 1 1 1
k j
![Page 9: Assignment 1 Andy Wang COP 4530: Data Structures, Algorithms, and Generic Programming.](https://reader038.fdocuments.in/reader038/viewer/2022110103/5697bf871a28abf838c88a17/html5/thumbnails/9.jpg)
Sieve Algorithm
4. for (k = 2; k <= sqrt(10); ++k)for (j = 2*k; j <= 10; j +=
k)
Unset b[j];
0 1 2 3 4 5 6 7 8 90 0 1 1 0 1 1 1 1 1
k j
![Page 10: Assignment 1 Andy Wang COP 4530: Data Structures, Algorithms, and Generic Programming.](https://reader038.fdocuments.in/reader038/viewer/2022110103/5697bf871a28abf838c88a17/html5/thumbnails/10.jpg)
Sieve Algorithm
4. for (k = 2; k <= sqrt(10); ++k)for (j = 2*k; j <= 10; j +=
k)
Unset b[j];
0 1 2 3 4 5 6 7 8 90 0 1 1 0 1 0 1 1 1
k j
![Page 11: Assignment 1 Andy Wang COP 4530: Data Structures, Algorithms, and Generic Programming.](https://reader038.fdocuments.in/reader038/viewer/2022110103/5697bf871a28abf838c88a17/html5/thumbnails/11.jpg)
Sieve Algorithm
4. for (k = 2; k <= sqrt(10); ++k)for (j = 2*k; j <= 10; j +=
k)
Unset b[j];
0 1 2 3 4 5 6 7 8 90 0 1 1 0 1 0 1 1 1
k j
![Page 12: Assignment 1 Andy Wang COP 4530: Data Structures, Algorithms, and Generic Programming.](https://reader038.fdocuments.in/reader038/viewer/2022110103/5697bf871a28abf838c88a17/html5/thumbnails/12.jpg)
Sieve Algorithm
4. for (k = 2; k <= sqrt(10); ++k)for (j = 2*k; j <= 10; j +=
k)
Unset b[j];
0 1 2 3 4 5 6 7 8 90 0 1 1 0 1 0 1 0 1
k j
![Page 13: Assignment 1 Andy Wang COP 4530: Data Structures, Algorithms, and Generic Programming.](https://reader038.fdocuments.in/reader038/viewer/2022110103/5697bf871a28abf838c88a17/html5/thumbnails/13.jpg)
Sieve Algorithm
4. for (k = 2; k <= sqrt(10); ++k)for (j = 2*k; j <= 10; j +=
k)
Unset b[j];
0 1 2 3 4 5 6 7 8 90 0 1 1 0 1 0 1 0 1
k
![Page 14: Assignment 1 Andy Wang COP 4530: Data Structures, Algorithms, and Generic Programming.](https://reader038.fdocuments.in/reader038/viewer/2022110103/5697bf871a28abf838c88a17/html5/thumbnails/14.jpg)
Sieve Algorithm
4. for (k = 2; k <= sqrt(10); ++k)for (j = 2*k; j <= 10; j +=
k)
Unset b[j];
0 1 2 3 4 5 6 7 8 90 0 1 1 0 1 0 1 0 1
k
![Page 15: Assignment 1 Andy Wang COP 4530: Data Structures, Algorithms, and Generic Programming.](https://reader038.fdocuments.in/reader038/viewer/2022110103/5697bf871a28abf838c88a17/html5/thumbnails/15.jpg)
Sieve Algorithm
4. for (k = 2; k <= sqrt(10); ++k)for (j = 2*k; j <= 10; j +=
k)
Unset b[j];
0 1 2 3 4 5 6 7 8 90 0 1 1 0 1 0 1 0 1
k j
![Page 16: Assignment 1 Andy Wang COP 4530: Data Structures, Algorithms, and Generic Programming.](https://reader038.fdocuments.in/reader038/viewer/2022110103/5697bf871a28abf838c88a17/html5/thumbnails/16.jpg)
Sieve Algorithm
4. for (k = 2; k <= sqrt(10); ++k)for (j = 2*k; j <= 10; j +=
k)
Unset b[j];
0 1 2 3 4 5 6 7 8 9 0 0 1 1 0 1 0 1 0 1
k j
![Page 17: Assignment 1 Andy Wang COP 4530: Data Structures, Algorithms, and Generic Programming.](https://reader038.fdocuments.in/reader038/viewer/2022110103/5697bf871a28abf838c88a17/html5/thumbnails/17.jpg)
Sieve Algorithm
4. for (k = 2; k <= sqrt(10); ++k)for (j = 2*k; j <= 10; j +=
k)
Unset b[j];
0 1 2 3 4 5 6 7 8 90 0 1 1 0 1 0 1 0 1
k j
![Page 18: Assignment 1 Andy Wang COP 4530: Data Structures, Algorithms, and Generic Programming.](https://reader038.fdocuments.in/reader038/viewer/2022110103/5697bf871a28abf838c88a17/html5/thumbnails/18.jpg)
Sieve Algorithm
4. for (k = 2; k <= sqrt(10); ++k)for (j = 2*k; j <= 10; j +=
k)
Unset b[j];
0 1 2 3 4 5 6 7 8 90 0 1 1 0 1 0 1 0 0
k j
![Page 19: Assignment 1 Andy Wang COP 4530: Data Structures, Algorithms, and Generic Programming.](https://reader038.fdocuments.in/reader038/viewer/2022110103/5697bf871a28abf838c88a17/html5/thumbnails/19.jpg)
Sieve Algorithm
4. for (k = 2; k <= sqrt(10); ++k)for (j = 2*k; j <= 10; j +=
k)
Unset b[j];
0 1 2 3 4 5 6 7 8 90 0 1 1 0 1 0 1 0 0
k
![Page 20: Assignment 1 Andy Wang COP 4530: Data Structures, Algorithms, and Generic Programming.](https://reader038.fdocuments.in/reader038/viewer/2022110103/5697bf871a28abf838c88a17/html5/thumbnails/20.jpg)
Sieve Algorithm
4. for (k = 2; k <= sqrt(10); ++k)for (j = 2*k; j <= 10; j +=
k)
Unset b[j];
0 1 2 3 4 5 6 7 8 90 0 1 1 0 1 0 1 0 0