Download presentation
Presentation is loading. Please wait.
Published byLőrinc Hegedűs Modified over 5 years ago
1
Counting Elements of Disjoint Sets: The Addition Rule
Lecture 30 Sections 6.3 Tue, Mar 20, 2007
2
Example: Inclusion/Exclusion
How many primes are there between 1 and 100? The non-primes must be multiples of 2, 3, 5, or 7, since the square root of 100 is 10.
3
A Lemma Lemma: Let n and d be positive integers. There are n/d multiples of d between 1 and n, where x represents the “floor” of x.
4
Example: Inclusion/Exclusion
Let A = {n | 1 n 100 and 2 divides n}. Let B = {n | 1 n 100 and 3 divides n}. Let C = {n | 1 n 100 and 5 divides n}. Let D = {n | 1 n 100 and 7 divides n}.
5
Example: Inclusion/Exclusion
By the Inclusion/Exclusion Rule, |A B C D| = |A| + |B| + |C| + |D| – |A B| – |A C| – |A D| – |B C| – |B D| – |C D| + |A B C| + |A B C| – |A B C D|.
6
Example: Inclusion/Exclusion
However, A B = {n | 1 n 100 and 6 | n}. A B C = {n | 1 n 100 and 30 | n}. B C D = {n | 1 n 100 and 105 | n}. And so on.
7
Example: Inclusion/Exclusion
Therefore, |A| = 100/2 = 50. |A B| = 100/6 = 16. |A B C| = 100/30 = 3. |B C D| = 100/105 = 0. And so on.
8
Example: Inclusion/Exclusion
The number of multiples of 2, 3, 5, and 7 is ( ) – ( ) + ( ) – (0) = 78
9
Example: Inclusion/Exclusion
This count includes 2, 3, 5, 7, which are prime. This count does not include 1, which is not prime. Therefore, the number of primes is 100 – – 1 = 25.
10
Primes.cpp Primes.cpp
11
Example: Inclusion/Exclusion
How many integers from 1 to 1000 are multiples of 6, 10, or 15? Let A = {n | 1 n 100 and 6 divides n}. Let B = {n | 1 n 100 and 10 divides n}. Let C = {n | 1 n 100 and 15 divides n}. What is A B? A C? B C? What is A B C?
12
Example: Inclusion/Exclusion
|B| = 1000/10 = 100. |C| = 1000/15 = 66. |A B| = 1000/30 = 33. |A C| = 1000/30 = 33. |B C| = 1000/30 = 33. |A B C| = 1000/30 = 33. Therefore, 266 numbers from 1 to 1000 are multiples of 6, 10, or 15.
13
Example: Inclusion/Exclusion
How many 8-bit numbers have either 1 in the 1st and 2nd positions, or 1 in the 1st and 3rd positions, or 1 in the 2nd, 3rd, and 4th positions?
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.