Combinatorics Combinatorics I Combinatorics II Product Rule Sum Rule I Sum Rule II
Total Page:16
File Type:pdf, Size:1020Kb
Combinatorics I Combinatorics Introduction Slides by Christopher M. Bourke Instructor: Berthe Y. Choueiry Combinatorics is the study of collections of objects. Specifically, counting objects, arrangement, derangement, etc. of objects along with their mathematical properties. Counting objects is important in order to analyze algorithms and Spring 2006 compute discrete probabilities. Originally, combinatorics was motivated by gambling: counting configurations is essential to elementary probability. Computer Science & Engineering 235 Introduction to Discrete Mathematics Sections 4.1-4.6 & 6.5-6.6 of Rosen [email protected] Combinatorics II Product Rule Introduction If two events are not mutually exclusive (that is, we do them separately), then we apply the product rule. A simple example: How many arrangements are there of a deck of 52 cards? Theorem (Product Rule) In addition, combinatorics can be used as a proof technique. Suppose a procedure can be accomplished with two disjoint A combinatorial proof is a proof method that uses counting subtasks. If there are n1 ways of doing the first task and n2 ways arguments to prove a statement. of doing the second, then there are n1 · n2 ways of doing the overall procedure. Sum Rule I Sum Rule II There is a natural generalization to any sequence of m tasks; If two events are mutually exclusive, that is, they cannot be done namely the number of ways m mutually exclusive events can occur at the same time, then we must apply the sum rule. is n1 + n2 + ··· nm−1 + nm Theorem (Sum Rule) We can give another formulation in terms of sets. Let If an event e1 can be done in n1 ways and an event e2 can be done A1,A2,...,Am be pairwise disjoint sets. Then in n2 ways and e1 and e2 are mutually exclusive, then the number of ways of both events occurring is |A1 ∪ A2 ∪ · · · ∪ Am| = |A1| + |A2| + ··· + |Am| n1 + n2 In fact, this is a special case of the general Principle of Inclusion-Exclusion. Principle of Inclusion-Exclusion (PIE) I Principle of Inclusion-Exclusion (PIE) II Introduction Introduction We cannot use the sum rule because we would be over counting the number of possible outcomes. Say there are two events, e1 and e2 for which there are n1 and n2 Instead, we have to count the number of possible outcomes of e1 possible outcomes respectively. and e2 minus the number of possible outcomes in common to both; i.e. the number of ways to do both “tasks”. Now, say that only one event can occur, not both. If again we think of them as sets, we have In this situation, we cannot apply the sum rule? Why? |A1| + |A2| − |A1 ∩ A2| Principle of Inclusion-Exclusion (PIE) III Principle of Inclusion-Exclusion (PIE) I Introduction Theorem More generally, we have the following. Theorem Lemma Let A1,A2,...,An be finite sets, then Let A, B be subsets of a finite set U. Then X |A1 ∪ A2 ∪ · · · ∪ An| = |Ai| 1. |A ∪ B| = |A| + |B| − |A ∩ B| i X 2. |A ∩ B| ≤ min{|A|, |B|} − |Ai ∩ Aj| i<j 3. |A \ B| = |A| − |A ∩ B| ≥ |A| − |B| X 4. |A| = |U| − |A| + |Ai ∩ Aj ∩ Ak| i<j<k 5. |A⊕B| = |A∪B|−|A∩B| = A+B−2|A∩B| = |A\B|+|B\A| − · · · 6. |A × B| = |A| × |B| n+1 +(−1) |A1 ∩ A2 ∩ · · · ∩ An| Principle of Inclusion-Exclusion (PIE) II Principle of Inclusion-Exclusion (PIE) III Theorem Theorem To illustrate, when n = 3, we have Each summation is over all i, pairs i, j with i < j, triples i, j, k |A1 ∪ A2 ∪ A3| = |A1| + |A2| + |A3| with i < j < k etc. − |A1 ∩ A2| + |A1 ∩ A3| + |A2 ∩ A3| +|A1 ∩ A2 ∩ A3| Principle of Inclusion-Exclusion (PIE) IV Principle of Inclusion-Exclusion (PIE) I Theorem Example I To illustrate, when n = 4, we have Example |A1 ∪ A2 ∪ A3 ∪ A4| = |A1| + |A2| + |A3| + |A4| h How many integers between 1 and 300 (inclusive) are − |A1 ∩ A2| + |A1 ∩ A3| + +|A1 ∩ A4| i 1. Divisible by at least one of 3, 5, 7? |A2 ∩ A3| + |A2 ∩ A4| + |A3 ∩ A4| 2. Divisible by 3 and by 5 but not by 7? h + |A1 ∩ A2 ∩ A3| + |A1 ∩ A2 ∩ A4| + 3. Divisible by 5 but by neither 3 nor 7? i |A ∩ A ∩ A | + |A ∩ A ∩ A | 1 3 4 2 3 4 Let −|A1 ∩ A2 ∩ A3 ∩ A4| A = {n | 1 ≤ n ≤ 300 ∧ 3 | n} B = {n | 1 ≤ n ≤ 300 ∧ 5 | n} C = {n | 1 ≤ n ≤ 300 ∧ 7 | n} Principle of Inclusion-Exclusion (PIE) II Principle of Inclusion-Exclusion (PIE) III Example I Example I By the principle of inclusion-exclusion, we have that How big are each of these sets? We can easily use the floor |A ∪ B ∪ C| = |A| + |B| + |C| function; h i |A| = b300/3c = 100 − |A ∩ B| + |A ∩ C| + |B ∩ C| |B| = b300/5c = 60 +|A ∩ B ∩ C| |C| = b300/7c = 42 For (1) above, we are asked to find |A ∪ B ∪ C|. It remains to find the final 4 cardinalities. All three divisors, 3, 5, 7 are relatively prime. Thus, any integer that is divisible by both 3 and 5 must simply be divisible by 15. Principle of Inclusion-Exclusion (PIE) IV Principle of Inclusion-Exclusion (PIE) V Example I Example I Using the same reasoning for all pairs (and the triple) we have For (2) above, it is enough to find |A ∩ B| = b300/15c = 20 |A ∩ C| = b300/21c = 14 |(A ∩ B) \ C| |B ∩ C| = b300/35c = 8 |A ∩ B ∩ C| = b300/105c = 2 By the definition of set-minus, Therefore, |(A ∩ B) \ C| = |A ∩ B| − |A ∩ B ∩ C| = 20 − 2 = 18 |A ∪ B ∪ C| = 100 + 60 + 42 − 20 − 14 − 8 + 2 = 162 Principle of Inclusion-Exclusion (PIE) VI Principle of Inclusion-Exclusion (PIE) I Example I Example II For (3) above, we are asked to find The principle of inclusion-exclusion can be used to count the number of onto functions. |B \ (A ∪ C)| = |B| − |B ∩ (A ∪ C)| Theorem By distributing B over the intersection, we get Let A, B be non-empty sets of cardinality m, n with m ≥ n. Then |B ∩ (A ∪ C)| = |(B ∩ A) ∪ (B ∩ C)| there are = |B ∩ A| + |B ∩ C| − |(B ∩ A) ∩ (B ∩ C)| n n n = |B ∩ A| + |B ∩ C| − |B ∩ A ∩ C| nm − (n − 1)m + (n − 2)m − · · · + (−1)n−1 1m 1 2 n − 1 = 20 + 8 − 2 = 26 i.e. Pn−1(−1)in(n − i)m onto functions f : A → B. So the answer is |B| − 26 = 60 − 26 = 34. i=0 i See textbook page 460. Principle of Inclusion-Exclusion (PIE) II Principle of Inclusion-Exclusion (PIE) III Example II Example II Example How many ways of giving out 6 pieces of candy to 3 children if To count how many there are, we apply the theorem and get (for each child must receive at least one piece? m = 6, n = 3), 3 3 This can be modeled by letting A represent the set of candies and 36 − (3 − 1)6 + (3 − 2)6 = 540 B be the set of children. 1 2 Then a function f : A → B can be interpreted as giving candy ai to child cj. Since each child must receive at least one candy, we are considering only onto functions. Derangements I Derangements II This can be modeled using derangements: permutations of objects such that no element is in its original position. Consider the hatcheck problem. For example, 21453 is a derangement of 12345, but 21543 is not. I An employee checks hats from n customers. Theorem I However, he forgets to tag them. The number of derangements of a set with n elements is I When customer’s check-out their hats, they are given one at random. 1 1 1 1 D = n! 1 − + − + ··· (−1)n n 1! 2! 3! n! What is the probability that no one will get their hat back? See textbook page 461. Derangements III The Pigeonhole Principle I Thus, the answer to the hatcheck problem is The pigeonhole principle states that if there are more pigeons than Dn there are roosts (pigeonholes), for at least one pigeonhole, more n! than two pigeons must be in it. Its interesting to note that Theorem (Pigeonhole Principle) 1 1 1 1 e−1 = 1 − + − + ··· + (−1)n ··· 1! 2! 3! n! If k + 1 or more objects are placed into k boxes, then there is at least one box containing two ore more objects. So that the probability of the hatcheck problem converges; D This is a fundamental tool of elementary discrete mathematics. It lim n = e−1 = .368 ... n→∞ n! is also known as the Dirichlet Drawer Principle. The Pigeonhole Principle II Generalized Pigeonhole Principle I It is seemingly simple, but very powerful. The difficulty comes in where and how to apply it. Theorem Some simple applications in computer science: If N objects are placed into k boxes then there is at least one box Calculating the probability of Hash functions having a containing at least I N collision. k I Proving that there can be no lossless compression algorithm compressing all files to within a certain ratio. Example Lemma In any group of 367 or more people, at least two of them must For two finite sets A, B there exists a bijection f : A → B if and have been born on the same date. only if |A| = |B|. Generalized Pigeonhole Principle II Generalized Pigeonhole Principle III Example A probabilistic generalization states that if n objects are randomly put into m boxes with uniform probability (each object is placed in Among 10 people, what is the probability that two or more will a given box with probability 1/m) then at least one box will hold have the same birthday? more than one object with probability, Here, n = 10 and m = 365 (ignore leapyears).