Combinatorics I Introduction. Combinatorics. Combinatorics I Motivating Example. Combinations. Product Rule. Permutations. Theorem (Product Rule)

Similar documents
Combinatorics II. Combinatorics. Product Rule. Sum Rule II. Theorem (Product Rule) Theorem (Sum Rule)

Lecture Overview. 2 Permutations and Combinations. n(n 1) (n (k 1)) = n(n 1) (n k + 1) =

Math 155 (Lecture 3)

Section 5.1 The Basics of Counting

CSE 191, Class Note 05: Counting Methods Computer Sci & Eng Dept SUNY Buffalo

CIS Spring 2018 (instructor Val Tannen)

Injections, Surjections, and the Pigeonhole Principle

Permutations & Combinations. Dr Patrick Chan. Multiplication / Addition Principle Inclusion-Exclusion Principle Permutation / Combination

Notes. Combinatorics. Combinatorics II. Notes. Notes. Slides by Christopher M. Bourke Instructor: Berthe Y. Choueiry. Spring 2006

(ii) Two-permutations of {a, b, c}. Answer. (B) P (3, 3) = 3! (C) 3! = 6, and there are 6 items in (A). ... Answer.

Recursive Algorithms. Recurrences. Recursive Algorithms Analysis

Permutations, Combinations, and the Binomial Theorem

Chapter 1 : Combinatorial Analysis

Bertrand s Postulate

The Random Walk For Dummies

Induction: Solutions

Chapter 6. Advanced Counting Techniques

Chapter 7 COMBINATIONS AND PERMUTATIONS. where we have the specific formula for the binomial coefficients:

Lecture 10: Mathematical Preliminaries

( ) GENERATING FUNCTIONS

Generating Functions. 1 Operations on generating functions

Math 475, Problem Set #12: Answers

Basic Counting. Periklis A. Papakonstantinou. York University

Intermediate Math Circles November 4, 2009 Counting II

Topic 5: Basics of Probability

Solutions to Final Exam

As stated by Laplace, Probability is common sense reduced to calculation.

What is Probability?

MATH 304: MIDTERM EXAM SOLUTIONS

Putnam Training Exercise Counting, Probability, Pigeonhole Principle (Answers)

Complex Numbers Solutions

Square-Congruence Modulo n

Books Recommended for Further Reading

ARRANGEMENTS IN A CIRCLE

1 Summary: Binary and Logic

MT5821 Advanced Combinatorics

Random Models. Tusheng Zhang. February 14, 2013

Exercises 1 Sets and functions

End-of-Year Contest. ERHS Math Club. May 5, 2009

Let us consider the following problem to warm up towards a more general statement.

Introduction To Discrete Mathematics

MT5821 Advanced Combinatorics

The Binomial Theorem

Lecture Notes for CS 313H, Fall 2011

In number theory we will generally be working with integers, though occasionally fractions and irrationals will come into play.

3.1 Counting Principles

REVIEW FOR CHAPTER 1

Axioms of Measure Theory

Discrete Mathematics for CS Spring 2007 Luca Trevisan Lecture 22

Infinite Sequences and Series

CSE 1400 Applied Discrete Mathematics Number Theory and Proofs

Homework 3. = k 1. Let S be a set of n elements, and let a, b, c be distinct elements of S. The number of k-subsets of S is

Week 5-6: The Binomial Coefficients

THE ASYMPTOTIC COMPLEXITY OF MATRIX REDUCTION OVER FINITE FIELDS

(A sequence also can be thought of as the list of function values attained for a function f :ℵ X, where f (n) = x n for n 1.) x 1 x N +k x N +4 x 3

Combinatorics and Newton s theorem

Solutions. tan 2 θ(tan 2 θ + 1) = cot6 θ,

arxiv: v1 [math.co] 23 Mar 2016

( ) = p and P( i = b) = q.

Combinatorially Thinking

6.3 Testing Series With Positive Terms

Final Review for MATH 3510

P1 Chapter 8 :: Binomial Expansion

Counting Well-Formed Parenthesizations Easily

CALCULATION OF FIBONACCI VECTORS

Sequences A sequence of numbers is a function whose domain is the positive integers. We can see that the sequence

IP Reference guide for integer programming formulations.

UC Berkeley Department of Electrical Engineering and Computer Sciences. EE126: Probability and Random Processes

18th Bay Area Mathematical Olympiad. Problems and Solutions. February 23, 2016

4.3 Growth Rates of Solutions to Recurrences

Randomized Algorithms I, Spring 2018, Department of Computer Science, University of Helsinki Homework 1: Solutions (Discussed January 25, 2018)

CS 330 Discussion - Probability

Lecture Notes for Analysis Class

A sequence of numbers is a function whose domain is the positive integers. We can see that the sequence

Discrete Mathematics for CS Spring 2005 Clancy/Wagner Notes 21. Some Important Distributions

(k) x n. n! tk = x a. (i) x p p! ti ) ( q 0. i 0. k A (i) n p

Lecture 2: April 3, 2013

It is always the case that unions, intersections, complements, and set differences are preserved by the inverse image of a function.

Recursive Algorithm for Generating Partitions of an Integer. 1 Preliminary

CHAPTER I: Vector Spaces

1 Hash tables. 1.1 Implementation

# fixed points of g. Tree to string. Repeatedly select the leaf with the smallest label, write down the label of its neighbour and remove the leaf.

Lecture 11: Pseudorandom functions

A Combinatorial Proof of a Theorem of Katsuura

Lecture 12: November 13, 2018

Sets and Probabilistic Models

1. n! = n. tion. For example, (n+1)! working with factorials. = (n+1) n (n 1) 2 1

MATH 324 Summer 2006 Elementary Number Theory Solutions to Assignment 2 Due: Thursday July 27, 2006

Solutions to Math 347 Practice Problems for the final

Problem Set 2 Solutions

subcaptionfont+=small,labelformat=parens,labelsep=space,skip=6pt,list=0,hypcap=0 subcaption ALGEBRAIC COMBINATORICS LECTURE 8 TUESDAY, 2/16/2016

4 The Sperner property.

Summer High School 2009 Aaron Bertram

Polynomial identity testing and global minimum cut

Mathematical Induction

SOLVED EXAMPLES

1 Generating functions for balls in boxes

CSE 21 Mathematics for

Problems from 9th edition of Probability and Statistical Inference by Hogg, Tanis and Zimmerman:

Summary: Congruences. j=1. 1 Here we use the Mathematica syntax for the function. In Maple worksheets, the function

Transcription:

Combiatorics I Itroductio Combiatorics Computer Sciece & Egieerig 235: Discrete Mathematics Christopher M. Bourke cbourke@cse.ul.edu Combiatorics is the study of collectios of objects. Specifically, coutig objects, arragemet, deragemet, etc. of objects alog with their mathematical properties. Coutig objects is importat i order to aalyze algorithms ad compute discrete probabilities. Origially, combiatorics was motivated by gamblig: coutig cofiguratios is essetial to elemetary probability. I additio, combiatorics ca be used as a proof techique. A combiatorial proof is a proof method that uses coutig argumets to prove a statemet. Combiatorics I Motivatig Combiatios How may arragemets are there of a deck of 52 cards? The stadard deck (The Mameluke deck) is thought to be 000 years old. Have all possible 52! bee dealt? Suppose that 5 billio people have dealt had every secod for the last 000 years. Percetage of deals that have occurred: 5 0 9 000 365.25 24 60 60 52!.9562 0 48 To eve deal % of all hads, we would require 5. 0 48 years (quidecillio). Choosig k elemets from a set of cardiality is a combiatio Notatios: C k C(, k) Combiatios are uordered! k ( k)!k! Commo usage: choosig sigletos: ( ) Choosig pairs: ( ) 2 ( ) 2 Permutatios Product Rule If two evets are ot mutually exclusive (that is, we do them separately), the we apply the product rule. Arragig elemets is a permutatio Number of permutatios:! Permutatios are ordered (Product Rule) Suppose a procedure ca be accomplished with two disjoit subtasks. If there are ways of doig the first task ad 2 ways of doig the secod, the there are 2 ways of doig the overall procedure.

Sum Rule I Sum Rule II If two evets are mutually exclusive, that is, they caot be doe at the same time, the we must apply the sum rule. (Sum Rule) If a evet e ca be doe i ways ad a evet e 2 ca be doe i 2 ways ad e ad e 2 are mutually exclusive, the the umber of ways of both evets occurrig is + 2 There is a atural geeralizatio to ay sequece of m tasks; amely the umber of ways m mutually exclusive evets ca occur is + 2 + m + m We ca give aother formulatio i terms of sets. Let A, A 2,..., A m be pairwise disjoit sets. The A A 2 A m A + A 2 + + A m I fact, this is a special case of the geeral Priciple of Iclusio-Exclusio. Priciple of Iclusio-Exclusio (PIE) I Itroductio Priciple of Iclusio-Exclusio (PIE) II Itroductio We caot use the sum rule because we would be over coutig the umber of possible outcomes. Say there are two evets, e ad e 2 for which there are ad 2 possible outcomes respectively. Now, say that oly oe evet ca occur, ot both. I this situatio, we caot apply the sum rule? Why? Istead, we have to cout the umber of possible outcomes of e ad e 2 mius the umber of possible outcomes i commo to both; i.e. the umber of ways to do both tasks. If agai we thik of them as sets, we have A + A 2 A A 2 Priciple of Iclusio-Exclusio (PIE) III Itroductio More geerally, we have the followig. Lemma Let A, B be subsets of a fiite set U. The. A B A + B A B 2. A B mi{ A, B } 3. A \ B A A B A B 4. A U A 5. A B A B A B A+B 2 A B A\B + B\A 6. A B A B Priciple of Iclusio-Exclusio (PIE) I Let A, A 2,..., A be fiite sets, the A A 2 A i A i A i A j i<j + A i A j A k i<j<k +( ) + A A 2 A

Priciple of Iclusio-Exclusio (PIE) II Priciple of Iclusio-Exclusio (PIE) III To illustrate, whe 3, we have Each summatio is over all i, pairs i, j with i < j, triples i, j, k with i < j < k etc. A A 2 A 3 A + A 2 + A 3 [ A A 2 + A A 3 + A 2 A 3 ] + A A 2 A 3 Priciple of Iclusio-Exclusio (PIE) IV Priciple of Iclusio-Exclusio (PIE) I I To illustrate, whe 4, we have A A 2 A 3 A 4 A + A 2 + A 3 + A 4 [ A A 2 + A A 3 + + A A 4 ] A 2 A 3 + A 2 A 4 + A 3 A 4 [ + A A 2 A 3 + A A 2 A 4 + ] A A 3 A 4 + A 2 A 3 A 4 A A 2 A 3 A 4 How may itegers betwee ad 300 (iclusive) are Let. Divisible by at least oe of 3, 5, 7? 2. Divisible by 3 ad by 5 but ot by 7? 3. Divisible by 5 but by either 3 or 7? A { 300 3 } B { 300 5 } C { 300 7 } Priciple of Iclusio-Exclusio (PIE) II I Priciple of Iclusio-Exclusio (PIE) III I How big are each of these sets? We ca easily use the floor fuctio; A 300/3 00 B 300/5 60 C 300/7 42 For () above, we are asked to fid A B C. By the priciple of iclusio-exclusio, we have that A B C A + B + C [ ] A B + A C + B C + A B C It remais to fid the fial 4 cardialities. All three divisors, 3, 5, 7 are relatively prime. Thus, ay iteger that is divisible by both 3 ad 5 must simply be divisible by 5.

Priciple of Iclusio-Exclusio (PIE) IV I Priciple of Iclusio-Exclusio (PIE) V I Usig the same reasoig for all pairs (ad the triple) we have Therefore, A B 300/5 20 A C 300/2 4 B C 300/35 8 A B C 300/05 2 For (2) above, it is eough to fid (A B) \ C By the defiitio of set-mius, (A B) \ C A B A B C 20 2 8 A B C 00 + 60 + 42 20 4 8 + 2 62 Priciple of Iclusio-Exclusio (PIE) VI I For (3) above, we are asked to fid B \ (A C) B B (A C) By distributig B over the itersectio, we get B (A C) (B A) (B C) B A + B C (B A) (B C) B A + B C B A C 20 + 8 2 26 So the aswer is B 26 60 26 34. Priciple of Iclusio-Exclusio (PIE) I II The priciple of iclusio-exclusio ca be used to cout the umber of oto fuctios. Let A {a, a 2,..., a m }, A m Let B {b, b 2,..., b }, B Say m (otherwise o oto fuctios exist) Observe: total umber of fuctios is m Cosider all fuctios such that o elemet maps to b : ( ) m Geeralize this: cosider all fuctios such that o elemet maps to b i for a particular i Priciple of Iclusio-Exclusio (PIE) II II There are such choices: Thus, the umber of fuctios that do ot map to (at least) a sigle elemet is: ( ) m We ve over couted though: whe we exclude b 2, the we are recoutig fuctios that also exclude b Need to restore couts: cosider pairs Cosider all fuctios such that o elemet maps to a pair of elemets: ( 2) m 2 Priciple of Iclusio-Exclusio (PIE) III II But observe: the first equatio is for fuctios that do ot map to at least oe elemet The secod equatio is for fuctios that do ot map to at least two elemets I.e. the first equatio took away too may fuctios; the secod restores this cout Cotiuig for i 3,..., we ca geeralize this.

Priciple of Iclusio-Exclusio (PIE) IV II Let A, B be o-empty sets of cardiality m, with m. The there are ( ) i ( i) m i i.e. m i0 ( ) ( ) ( ) ( ) m + ( 2) m + ( ) m 2 oto fuctios f : A B. Priciple of Iclusio-Exclusio (PIE) V II This is related to Stirlig Numbers of the Secod Kid Defiitio Stirlig umbers of the secod kid represet the umber of ways that you ca partitio elemets ito k o-empty subsets ad is defied as S(, k) { } k k! k ( k ( ) j j j0 Oly differece: for j k, (k j) 0 ) (k j) Stirlig umbers partitio ito uordered subsets Fuctio mappig requires orderig mapped elemets! possible mappigs, so the k! cacels out Priciple of Iclusio-Exclusio (PIE) VI II Priciple of Iclusio-Exclusio (PIE) VII II How may ways of givig out 6 pieces of cady to 3 childre if each child must receive at least oe piece? This ca be modeled by lettig A represet the set of cadies ad B be the set of childre. To cout how may there are, we apply the theorem ad get (for m 6, 3), 3 6 ( ) 3 ( ) 3 (3 ) 6 + 2 (3 2) 6 540 The a fuctio f : A B ca be iterpreted as givig cady a i to child c j. Sice each child must receive at least oe cady, we are cosiderig oly oto fuctios. Deragemets I Deragemets II Cosider the hatcheck problem. A employee checks hats from customers. However, he forgets to tag them. Whe customer s check-out their hats, they are give oe at radom. What is the probability that o oe will get their hat back? This ca be modeled usig deragemets: permutatios of objects such that o elemet is i its origial positio. The umber of deragemets of a set with elemets is [ D!! + 2! 3! + ] ( )!

Deragemets III Thus, the aswer to the hatcheck problem is Its iterestig to ote that D! e! + 2! 3! + + ( )! So that the probability of the hatcheck problem coverges; D lim e.3679...! Deragemets IV The formula for deragemets ca be derived as follows. The umber of deragemets is equal to the umber of permutatio (!) mius ay permutatio that leaves at least oe elemet i its origial place (o deragemets). Total umber of permutatios:! Number of permutatios such that at least elemet is i place: ( )!!! We ve over corrected; add back permutatios such that at least 2 elemets are i place: + ( 2)!! 2 2! Deragemets V The Pigeohole Priciple I I geeral: ( ) k ( k)!! k k! Last term will be whe k which is the idetity permutatio The pigeohole priciple states that if there are more pigeos tha there are roosts (pigeoholes), for at least oe pigeohole, at least two pigeos must be i it. (Pigeohole Priciple) If k + or more objects are placed ito k boxes, the there is at least oe box cotaiig two or more objects. This is a fudametal tool of elemetary discrete mathematics. It is also kow as the Dirichlet Drawer Priciple. The Pigeohole Priciple II Geeralized Pigeohole Priciple I It is seemigly simple, but very powerful. The difficulty comes i where ad how to apply it. Some simple applicatios i computer sciece: Calculatig the probability of Hash fuctios havig a collisio. Provig that there ca be o lossless compressio algorithm compressig all files to withi a certai ratio. Lemma For two fiite sets A, B there exists a bijectio f : A B if ad oly if A B. If N objects are placed ito k boxes the there is at least oe box cotaiig at least N k I ay group of 367 or more people, at least two of them must have bee bor o the same date.

Probablistic Pigeohole Priciple I Probablistic Pigeohole Priciple II A probabilistic geeralizatio states that if objects are radomly put ito m boxes with uiform probability (each object is placed i a give box with probability /m) the at least oe box will hold more tha oe object with probability, m! (m )!m Amog 0 people, what is the probability that two or more will have the same birthday? Here, 0 ad m 365 (igore leapyears). Thus, the probability that two will have the same birthday is 365!.69 (365 0)!3650 So less tha a 2% probability! Oly 23 people required for a better tha 50% (50.7%) probability With oly 57, we have a better tha 99% probability Probablistic Pigeohole Priciple III Probablistic Pigeohole Priciple IV Derivatio: cosider the -permutatios of m pigeoholes: How may people do we eed to have a better tha 50% probability? For what is 365! (365 )!365.50 Surprisigly small: for 23, probability is greater tha 50.7%! Kow as the Birthday paradox P (m, ) m! m(m )(m 2) (m + ) (m )! These are the pigeoholes that we will evely distribute objects ito. Order is importat because the objects are distict. We place each object ito distict pigeohole with probability m, so i total: ( ) m m Thus the probability is: m! (m )!m Probablistic Pigeohole Priciple V Alteratively: cosider choosig bis (from a total of m bis to map objects to: ( ) m! (m )!! But ow cosider actually mappig objects o,..., o to each bi. Here, order matters, but i additio, we oly wat to map oe object to oe bucket. That is, we wat to cout the total umber of oe-to-oe fuctios from o,..., o to the bis we chose. Thus:! (m )!!!! (m )! Probablistic Pigeohole Priciple VI Thus the probability of a radom allocatio resultig i all bis havig 0 or objects is! (m )! m! m (m )!m Agai, viewig allocatio of objects to buckets, how may fuctios i total are there? m

Pigeohole Priciple I I Pigeohole Priciple II I Show that i a room of people with certai acquaitaces, some pair must have the same umber of acquaitaces. Note that this is equivalet to showig that ay symmetric, irreflexive relatio o elemets must have two elemets with the same umber of relatios. We ll show by cotradictio usig the pigeohole priciple. Assume to the cotrary that every perso has a differet umber of acquaitaces; 0,,..., (we caot have here because it is irreflexive). Are we doe? No, sice we oly have people, this is okay (i.e. there are possibilities). We eed to use the fact that acquaitaceship is a symmetric, irreflexive relatio. I particular, some perso kows 0 people while aother kows people. I other words, someoe kows everyoe, but there is also a perso that kows o oe. Thus, we have reached a cotradictio. Pigeohole Priciple I II Show that i ay list of te oegative itegers, a 0,..., a 9, there is a strig of cosecutive items of the list a l, a l+,..., a k whose sum is divisible by 0. Cosider the followig 0 umbers. a 0 a 0 + a a 0 + a + a 2. a 0 + a + a 2 + + a 9 Pigeohole Priciple II II Otherwise, we observe that each of these umbers must be i oe of the cogruece classes mod 0, 2 mod 0,..., 9 mod 0 By the pigeohole priciple, at least two of the itegers above must lie i the same cogruece class. Say a, a lie i the cogruece class k mod 0. The (a a ) k k(mod 0) ad so the differece (a a ) is divisible by 0. If ay oe of them is divisible by 0 the we are doe. Pigeohole Priciple I III Say 30 buses are to trasport 2000 Corhusker fas to Colorado. Each bus has 80 seats. Show that. Oe of the buses will have 4 empty seats. 2. Oe of the buses will carry at least 67 passegers. For (), the total umber of seats is 30 80 2400 seats. Thus there will be 2400 2000 400 empty seats total. Pigeohole Priciple II III By the geeralized pigeohole priciple, with 400 empty seats amog 30 buses, oe bus will have at least 400 4 30 empty seats. For (2) above, by the pigeohole priciple, seatig 2000 passegers amog 30 buses, oe will have at least 2000 67 30 passegers.

Permutatios I Permutatios II A permutatio of a set of distict objects is a ordered arragemet of these objects. A ordered arragemet of r elemets of a set is called a r-permutatio. The umber of r permutatios of a set with distict elemets is r P (, r) ( i) ( )( 2) ( r + ) i0 It follows that I particular, P (, r)! ( r)! P (, )! Agai, ote here that order is importat. It is ecessary to distiguish i what cases order is importat ad i which it is ot. Permutatios I Permutatios I Variatio How may pairs of dace parters ca be selected from a group of 2 wome ad 20 me? The first woma ca be partered with ay of the 20 me. The secod with ay of the remaiig 9, etc. To parter all 2 wome, we have P (20, 2) Aother perspective: choose 2 me to iclude, the order them What if we allowed all 32 people to pair up i ay combiatio? Number of permutatios: 32! But a give pair, AB is the same as BA Correct for each pair: 2 6 Now each pair s orderig also does t matter Correct for each such permutatio: 6! 32! 2 6 6! Permutatios II Variatio Permutatios II Geeralizatio: give k objects, how may ways are there to form groups of size k? (k)! (k!)! I how may ways ca the Eglish letters be arraged so that there are exactly te letters betwee a ad z? The umber of ways of arragig 0 letters betwee a ad z is P (24, 0). Sice we ca choose either a or z to come first, there are 2P (24, 0) arragemets of this 2-letter block. For the remaiig 4 letters, there are P (5, 5) 5! arragemets. I all, there are 2P (24, 0) 5!

Permutatios III Permutatios III - Cotiued How may permutatios of the letters a, b, c, d, e, f, g cotai either the patter bge or eaf? The umber of total permutatios is P (7, 7) 7!. If we fix the patter bge, the we ca cosider it as a sigle block. Thus, the umber of permutatios with this patter is P (5, 5) 5!. Fixig the patter eaf we have the same umber, 5!. Thus we have Is this correct? 7! 2(5!) No. We have take away too may permutatios: oes cotaiig both eaf ad bge. Here there are two cases, whe eaf comes first ad whe bge comes first. Permutatios III - Cotiued Combiatios I Defiitio eaf caot come before bge, so this is ot a problem. If bge comes first, it must be the case that we have bgeaf as a sigle block ad so we have 3 blocks or 3! arragemets. Altogether we have 7! 2(5!) + 3! 4806 Whereas permutatios cosider order, combiatios are used whe order does ot matter. Defiitio A k-combiatio of elemets of a set is a uordered selectio of k elemets from the set. A combiatio is simply a subset of cardiality k. Combiatios II Defiitio Combiatios III Defiitio The umber of k-combiatios of a set with cardiality with 0 k is! C(, k) k ( k)!k! Note: the otatio, ( k) is read, choose k. I T EX use { choose k} (with the forward slash). A useful fact about combiatios is that they are symmetric. etc. ( ) ( ) ( ) ( ) 2 2

Combiatios IV Defiitio Combiatios I I This is formalized i the followig corollary. Corollary Let, k be oegative itegers with k, the ( ) ( ) k k I the Powerball lottery, you pick five umbers betwee ad 59 ad a sigle powerball umber betwee ad 35. How may possible plays are there? Order here does t matter, so the umber of ways of choosig five regular umbers is ( ) 59 5 Combiatios II I Combiatios I II We ca choose amog 35 power ball umbers. These evets are ot mutually exclusive, thus we use the product rule. ( ) 59 59! 35 35 75, 223, 50 5 (59 5)!5! So the odds of wiig are 75, 223, 50 < 5.70699 0 9.00000000570699675% I a sequece of 0 coi tosses, how may ways ca 3 heads ad 7 tails come up? The umber of ways of choosig 3 heads out of 0 coi tosses is ( ) 0 3 Combiatios II II However, this is the same as choosig 7 tails out of 0 coi tosses; ( ) 0 3 ( ) 0 20 7 This is a perfect illustratio of the previous corollary. Combiatios III II Aother perspective: what is the correspodig probability of 0 coi tosses edig up with 3 heads/7 tails? It is the umber of such outcomes divided by the total umber of possible outcomes: C(0, 7) 2 0 Why 2 0? Each toss was a idepedet evet with 2 possible outcomes. Aother perspective: the total umber of outcomes is equal to the total umber of ways to choose: (0 tails, 0 heads), ( tails, 9 heads), (2 tails, 8 heads),... (0 tails, 0 heads) Which is: 0 i0 ( ) 0 2 0 i

Combiatios IV II Gambler s Fallacy Say that we ve flipped a coi ad heads has appeared 9 times i a row. What is the probability that the ext flip will be tails? Heads? That is, the sum of biomial coefficiets is equal to 2 Each evet is idepedet: there is a fudametal differece betwee probabilities ivolvig a sequece of evets (parlays) ad the probability of a evet give a prior sequece. August 8, 93 Mote Carlo casio: black appeared 5 times i a row. Gamblers rushed to bet o red. Black would appear a total of 26 times i a row; may lost their bets thikig that red was due. Krusty o why he bet agaist the Harlem Globetrotters: I thought the Geerals were due! Combiatios I III Combiatios II III How may possible committees of five people ca be chose from 20 me ad 2 wome if. if exactly three me must be o each committee? 2. if at least four wome must be o each committee? For (), we must choose 3 me from 20 the two wome from 2. These are ot mutually exclusive, thus the product rule applies. ( )( ) 20 2 3 2 Combiatios III III Combiatios IV III For (2), we cosider two cases; the case where four wome are chose ad the case where five wome are chose. These two cases are mutually exclusive so we use the additio rule. For the first case we have ( )( ) 20 2 4 Ad for the secod we have ( )( ) 20 2 0 5 Together we have ( 20 )( 2 4 ) + ( 20 0 )( 2 5 ) 0, 692

Biomial Coefficiets I Itroductio Biomial Coefficiets II Itroductio The umber of r-combiatios, ( r) is also called a biomial coefficiet. They are the coefficiets i the expasio of the expressio (multivariate polyomial), (x + y). A biomial is a sum of two terms. (Biomial ) Let x, y be variables ad let be a oegative iteger. The (x + y) j0 x j y j j Biomial Coefficiets III Itroductio Expadig the summatio, we have (x + y) ( ) 0 x + ( ) x y + ( 2) x 2 y 2 + + ( ) xy + ( ) y For example, (x + y) 3 (x + y)(x + y)(x + y) (x + y)(x 2 + 2xy + y 2 ) x 3 + 3x 2 y + 3xy 2 + y 3 ) Biomial Coefficiets I What is the coefficiet of the term x 8 y 2 i the expasio of (3x + 4y) 20? By the Biomial, we have 20 ( ) 20 (3x + 4y) j (3x) 20 j (4y) j j0 So whe j 2, we have ( ) 20 (3x) 8 (4y) 2 2 so the coefficiet is 20! 2!8! 38 4 2 386687326750720. Biomial Coefficiets I More Biomial Coefficiets II More A lot of useful idetities ad facts come from the Biomial. Corollary k k0 ( ) k k x k k k0 2 k k k0 k0 2 0 ( + x) 3 Ad may more.

Biomial Coefficiets III More Most of these ca be prove by either iductio or by a combiatorial argumet. (Vadermode s Idetity) Let m,, r be oegative itegers with r ot exceedig either m or. The ( ) m + r ( )( ) m r r k k k0 Biomial Coefficiets IV More Corollary If is a oegative iteger, the Corollary ( ) 2 k0 2 k Let, r be oegative itegers, r. The + r + jr ( ) j r Biomial Coefficiets I Pascal s Idetity & Triagle The followig is kow as Pascal s Idetity which gives a useful idetity for efficietly computig biomial coefficiets. (Pascal s Idetity) Let, k Z + with k. The ( ) ( ) + k k + k Pascal s Idetity forms the basis of a geometric object kow as Pascal s Triagle. Pascal s Triagle ( 0 0) ( ) ( 0 ) ( 2 ) ( 2 ) ( 2 0 2) ( 3 ) ( 3 ) ( 3 ) ( 3 0 2 3) ( 4 ) ( 4 ) ( 4 ) ( 4 ) ( 4 0 2 3 4) ( 5 ) ( 5 ) ( 5 ) ( 5 ) ( 5 ) ( 5 0 2 3 4 5) Pascal s Triagle Pascal s Triagle 2 3 3 4 6 4 5 0 0 5 ( 0 0) ( ) ( 0 ) ( 2 ) ( 2 ) ( 2 0 2) ( 3 ) ( 3 ) ( 3 ) ( 3 0 2 3) ( 3 ) ( 2 + 3 ) ( 3 4 3) ( 4 ) ( 4 ) ( 4 ) ( 4 ) ( 4 0 2 3 4) ( 5 ) ( 5 ) ( 5 ) ( 5 ) ( 5 ) ( 5 0 2 3 4 5)

Geeralized Permutatios I Geeralized Combiatios I Sometimes we are cocered with permutatios ad combiatios i which repetitios are allowed. The umber of r-permutatios of a set of objects with repetitio allowed is r. There are ( + r r ) + r r-combiatios from a set with elemets whe repetitio of elemets is allowed. Geeralized Combiatios II To see this cosider: bars (so cells that represet that types of items) r stars: (if x stars are placed ito a give cell, its the umber of elemets of that type that we choose) So + r thigs to be arraged However, we ve over couted: stars ad bars are idistiguishable Ay sequece of cotiguous stars/bars is the same uder ay orderig, so we eed to divide out by permutatios of ad r: ( + r)! ( )!r! ( + r)! ( + r r)!r! + r r Geeralized Combiatios I There are 30 varieties of douts from which we wish to buy a doze. How may possible orders are there? Here 30 ad we wish to choose r 2. Order does ot matter ad repetitios are possible, so we apply the previous theorem to get that there are ( ) 30 + 2 possible orders. 2 Geeralized Combiatios II Geeralized Combiatios III The umber of differet permutatios of objects where there are idistiguishable objects of type, 2 of type 2,..., ad k of type k is!! 2! k! A equivalet way of iterpretig this theorem is the umber of ways to distribute distiguishable objects ito k distiguishable boxes so that i objects are placed ito box i for i, 2,..., k. How may permutatios of the word Mississippi are there? Mississippi cotais 4 distict letters, M, i, s ad p; with, 4, 4, 2 occurreces respectively. Therefore there are permutatios.!!4!4!2!

Distiguishable Objects ito Distiguishable Boxes : how may ways are there to deal a 52 card deck ito 5 card hads to four players? ( )( )( )( ) 52 47 42 37 5 5 5 5 The umber of ways to distribute distiguishable objects ito k distiguishable boxes such that each box has i objects for i,..., k is!! 2! k! Idistiguishable Objects ito Distiguishable Boxes Idistiguishable objects ito distiguishable boxes: equivalet to -combiatios of k elemets whe repetitio is allowed (parameters are switched). The umber of ways to distribute idistiguishable objects ito k distiguishable boxes is ( ) ( ) k + k + k Card example: the 5 box should cotai the remaiig 32 udealt cards Distiguishable Objects ito Idistiguishable Boxes Idistiguishable Objects ito Idistiguishable Boxes I Distiguishable objects ito idistiguishable boxes: ot the same as vice versa. Equivalet to Stirlig umbers of the 2d kid (the k! factor recogizes that boxes are idistiguishable ad corrects for it) The umber of ways to distribute distiguishable objects ito k idistiguishable boxes is k! k ( k ( ) j j j0 ) (k j) Far more complicated : 6 copies of the same book ito 4 idetical boxes: (6), (5, ), (4, 2), (4,, ), (3, 3),... Equivalet to partitios of a iteger sum No closed form, requires a geeratig fuctio: Geeratig Fuctio I Related: Set Partitios I How may ways are there to make chage for a dollar (usig half-dollars, quarters, dimes, ickels, peies)? The geeratig fuctio: C(x) ( x)( x 5 )( x 0 )( x 25 )( x 50 ) gives us the aswer: for ay amout of chage c, we wat the coefficiet of x c i the expasio of C(x). For c 00, the coefficiet of x 00 is 292. The umber of ways to partitio a set ito disjoit o-empty subsets (such that their uio is the origial set). : S {, 2, 3} the the partitios are: {{a}, {b}, {c}} {{a}, {b, c}} {{b}, {a, c}} {{c}, {a, b}} {{a, b, c}}

Related: Set Partitios II Related: Set Partitios III The umber of ways to partitio a set of size ito disjoit o-empty subsets correspods to the -th Bell Number: B + k0 B k k Note: B 0, B, B 2 2, B 3 5, B 4 5, 52, 203, 877, 440, 247, 5975,... Basic Idea: Cosider a ew elemet e + It could be i its ow partitio, thus there are ( 0) B partitioigs of the remaiig elemets It could be paired with oe other elemet, leavig ( ) B partitioigs of remaiig elemets It could be paired with two other elemet, leavig ( 2) B 2 partitioigs of remaiig elemets All the way to ( ) B0 Each Bell umber is the sum of Stirlig umbers of the secod kid: { } B k k0 Idea: Stirlig umbers give the umber of ways to partitio ito k o-empty subsets; summig over all such k gives us the formula. Geeratig Permutatios & Combiatios I Itroductio Geeratig Permutatios & Combiatios II Itroductio I geeral, it is iefficiet to solve a problem by cosiderig all permutatios or combiatios sice there are a expoetial umber of such arragemets. Nevertheless, for may problems, o better approach is kow. Whe exact solutios are eeded, back-trackig algorithms are used. Geeratig permutatios or combiatios are sometimes the basis of these algorithms. (Travelig Sales Perso Problem) Cosider a salesma that must visit differet cities. He wishes to visit them i a order such that his overall distace traveled is miimized. Geeratig Permutatios & Combiatios III Itroductio This problem is oe of hudreds of NP-complete problems for which o kow efficiet algorithms exist. Ideed, it is believed that o efficiet algorithms exist. (Actually, Euclidea TSP is ot eve kow to be i NP!) The oly kow way of solvig this problem exactly is to try all! possible routes. We give several algorithms for geeratig these combiatorial objects. Geeratig Combiatios I Recall that combiatios are simply all possible subsets of size r. For our purposes, we will cosider geeratig subsets of The algorithm works as follows. Start with {,..., r} {, 2, 3,..., } Assume that we have a a 2 a r, we wat the ext combiatio. Locate the last elemet a i such that a i r + i. Replace a i with a i +. Replace a j with a i + j i for j i +, i + 2,..., r.

Geeratig Combiatios II Geeratig Combiatios III The followig is pseudocode for this procedure. Algorithm (Next r-combiatio) Iput : A set of elemets ad a r-combiatio, a a r. Output i r 2 while a i r + i do 3 i i 4 ed 5 a i a i + 6 for j (i + )... r do 7 a j a i + j i 8 ed : The ext r-combiatio. Fid the ext 3-combiatio of the set {, 2, 3, 4, 5} after {, 4, 5} Here, a, a 2 4, a 3 5. The last i such that a i 5 3 + i is. Thus, we set a a + 2 a 2 a + 2 3 a 3 a + 3 4 So the ext r-combiatio is {2, 3, 4}. Geeratig Permutatios Geeratig Permutatios Lexicographic Order Algorithm (Next Permutatio (Lexicographic Order)) The text gives a algorithm to geerate permutatios i lexicographic order. Essetially the algorithm works as follows. Give a permutatio, Choose the left-most pair a j, a j+ where a j < a j+. Choose the least item to the right of a j greater tha a j. Swap this item ad a j. Arrage the remaiig (to the right) items i order. Geeratig Permutatios I Iput : A set of elemets ad a r-permutatio, a a r. Output j 2 while a j > a j+ do 3 j j 4 ed : The ext r-permutatio. //j is the largest subscript with a j < a j+ 5 k 6 while a j > a k do 7 k k 8 ed //a k is the smallest iteger greater tha a j to the right of a j 9 swap(a j, a k ) 0 r s j + 2 while r > s do 3 swap(a r, a s) 4 r r 5 s s + 6 ed Geeratig Permutatios II Ofte there is o reaso to geerate permutatios i lexicographic order. Moreover, eve though geeratig permutatios is iefficiet i itself, lexicographic order iduces eve more work. A alterate method is to fix a elemet, the recursively permute the remaiig elemets. Aother method has the followig attractive properties. It is bottom-up (o-recursive). It iduces a miimal-chage betwee each permutatio. The algorithm is kow as the Johso-Trotter algorithm. We associate a directio to each elemet, for example: 3 2 4 A compoet is mobile if its directio poits to a adjacet compoet that is smaller tha itself. Here 3 ad 4 are mobile ad ad 2 are ot.

Geeratig Permutatios III Johso-Trotter s Algorithm (JohsoTrotter) A: cosider permutatios of (,..., 6): Iput : A iteger. Output π 2... : All possible permutatios of, 2,.... 2 while There exists a mobile iteger k π do 3 k largest mobile iteger 4 swap k ad the adjacet iteger k poits to 5 reverse directio of all itegers > k 6 Output π 7 ed 4, 3,, 2, 6, 5 2, 6 are mobile, so swap 6, 5; o orietatio chages: 4, 3,, 2, 5, 6 2 is the oly mobile elemet, flip, 2; orietatio of 4, 3, 5, 6 gets reversed: 4, 3, 2,, 5, 6 More s I I As always, the best way to lear ew cocepts is through practice ad examples. How may bit strigs of legth 4 are there such that ever appears as a substrig? We ca represet the set of strig graphically usig a tree. I II : Coutig Fuctios I I 0 0 0 0 0 0 Let S, T be sets such that S, T m. How may fuctios are there mappig f : S T? How may of these fuctios are oe-to-oe? 0 0 0 0 0 00000000000000 0000000 A fuctio simply maps each s i to some t j, thus for each we ca choose to sed it to ay of the elemets i T. Therefore, the umber of such bit strig is 8.

: Coutig Fuctios I II : Coutig Fuctios I III Each of these is a idepedet evet, so we apply the multiplicatio rule; m } m {{ m } m times If we wish f to be oe-to-oe, we must have that m, otherwise we ca easily aswer 0. Now, each s i must be mapped to a uique elemet i T. For s, we have m choices. However, oce we have made a mappig (say t j ), we caot map subsequet elemets to t j agai. I particular, for the secod elemet, s 2, we ow have m choices. Proceedig i this maer, s 3 will have m 2 choices, etc. Thus we have m (m ) (m 2) (m ( 2)) (m ( )) A alterative way of thikig about this problem is by usig the choose operator: we eed to choose elemets from a set of size m for our mappig; ( ) m m! (m )!! : Coutig Fuctios I IV : Coutig Fuctios II Oce we have chose this set, we ow cosider all permutatios of the mappig, i.e.! differet mappigs for this set. Thus, the umber of such mappigs is m! (m )!!! m! (m )! Recall this questio from the st exam: Let S {, 2, 3}, T {a, b}. How may oto fuctios are there mappig S T? How may oe-to-oe fuctios are there mappig T S? : Coutig Primes I : Coutig Primes II Give a estimate for how may 70 bit primes there are. Recall that the umber of primes ot more tha is about l Usig this fact, the umber of primes ot exceedig 2 70 is 2 70 l 2 70 However, we have over couted we ve couted 69-bit, 68-bit, etc primes as well. The umber of primes ot exceedig 2 69 is about Thus the differece is 2 70 l 2 70 269 2 69 l 2 69.9896 09 l 269

: More sets I : More sets II How may itegers i the rage k 00 are divisible by 2 or 3? Let A {x x 00, 2 x} B {y x 00, 3 y} Clearly, A 50, B 00 3 33, so is it true that A B 50 + 33 83? No; we ve over couted agai ay iteger divisible by 6 will be i both sets. How much did we over cout? The umber of itegers betwee ad 00 divisible by 6 is 6, so the aswer to the origial questio is 00 6 A B (50 + 33) 6 67