Mathematics for Computer Science MIT 6.042J/18.062J Combinatorics I Copyright © Radhika Nagpal, 2002. Prof. Albert Meyer & Dr. Radhika Nagpal
Counting in Algorithms How many different ways can 3 colors be assigned to an n-node graph? How many different mappings need to be checked to see if two arbitrary n-node graphs are isomorphic? How many stable pairings are there between n girls and n boys?
Counting in Algorithms What is the minimum number of binary comparisons needed to sort n numbers? i.e. what is the best any algorithm could possibly do?
Counting in Games How many different initial positions exist for a rubix cube? How many different chess boards can exist after 3 moves? After 6 moves? How many weighings do you need to find one counterfeit coin amongst 12 coins?
Counting in Probability Probability of a special event occurring # of special events # total events (simplified view) What is the probability of getting two jacks in a five card draw poker game? =
Counting Techniques Bijections Sum Rule, Inclusion-Exclusion Product Rule Pigeonhole Principle Trees Permutations
Counting Techniques Bijections Sum Rule, Inclusion-Exclusion Product Rule Pigeonhole Principle Trees Permutations
Bijections If f is a bijection from A to B, then |A| = |B| A B … … f
If sets A and B are disjoint, then Sum Rule If sets A and B are disjoint, then |A U B| = |A| + |B| A B
If sets A and B are disjoint, then Sum Rule If sets A and B are disjoint, then |A U B| = |A| + |B| What if A and B are not disjoint? A B
Inclusion-Exclusion (2 Sets) For two arbitrary sets A and B A B
Inclusion-Exclusion (2 Sets) Also, |A U B| < |A| + |B| A B
Inclusion-Exclusion (3 Sets) A B C
Product Rule If |A| = m and |B| = n, then |A x B| = mn
Product Rule If |A| = m and |B| = n, then |A x B| = mn A = {a, b, c}, B = {1, 2, 3}
Product Rule If |A| = m and |B| = n, then |A x B| = mn A = {a, b, c}, B = {1, 2, 3} A x B = {(a,1) (a,2) (a,3) (b,1) (b,2) (b,3) (c,1) (c,2) (c,3)}
Product Rule If |A| = m and |B| = n, then |A x B| = mn A = {a, b, c}, B = {1, 2, 3} A x B = {(a,1) (a,2) (a,3) (b,1) (b,2) (b,3) (c,1) (c,2) (c,3)} So |A x B| = 9
Product Rule: Counting Strings The number of 4-bit strings from the alphabet A = {0,1} = |A x A x A x A| = 2.2.2.2 =
Product Rule: Tree 1111 1110 1101 1100 1011 … 0000 1 1
Product Rule: Counting Strings The number of n-bit strings from the alphabet A of size m
Example Given a set A, how many subsets are there? i.e. |P(A)| ? A = {a, b, c} P(A) = {{} {a} {b} {c} {a,b} {b,c} {c,a} {a,b,c}}
Bijection: P(A) and Binary Strings A = {a1 a2 a3 a4 a5……an} Binary String = 1 0 1 0 1 00..0 Subset of A = {a1, a3, a5}
Bijection: P(A) and Binary Strings A = {a1 a2 a3 a4 a5……an} Binary String = 1 0 1 0 1 00..0 Subset of A = {a1, a3, a5} Exact correspondence Number of n-bit binary strings = If |A| =n, then P(A) =
Pigeonhole Principle If you have n pigeons and m holes and n > m, then at least one hole must have two pigeons
Example: Birthdays If 366 people, in the room then two must have the same birthday (day/month). If 731 people, then 3 must have same birthday…
In-class Problems
Summary Sum rule Inclusion Exclusion Product Rule Pigeonhole Principle If |A| = m and |B| = n, then |A x B| = mn Pigeonhole Principle If n pigeons, m holes, n>m, then must be at least 2 in some hole - If sets A and B are disjoint, then |A U B| = |A| + |B|
Counting Strings with 7s False Argument Counted numbers with multiple 7s many times
A Correct Argument All 4-digit numbers with at least one 7 = all possible 4-digit numbers, minus 4-digit numbers with no 7s. Both of these are easy to count
An Alternate Counting? Is this argument correct?
Algebra or Calculator Are these two the same?
How do you know if it is correct? Many ways of counting the same thing How do you know you got it right? Algebra, calculator Prove it!
Proving Correctness Prove that you counting correctly Prove that you counted everything Prove that you didn’t count anything twice
Another Pigeonhole Problem Say that we have 6 people, such that every pair of people are either friends or strangers, then there is always a set of 3 friends or 3 strangers
Restated as a Graph problem In a 6-node complete graph, where every edge is colored red or blue, there always exists either a red triangle or a blue triangle
Not always so easy…. How many people do you need before you are guaranteed to have a set of six that know each other? Paul Erdos’s answer: If aliens required you answer this in a year, throw in the towel and strike preemptively…. Ramsey numbers R(3,3)=6 R(6,6)=??
Next lecture Trees, Permutations, r-Permutations Importance of mapping Functions and strings How many possible functions, How many possible bijections?
Important technique: Matching Make a mapping between a given problem and a set of known cardinality (or at least one we know how to count…) Functions->binary strings Lists->trees Graphs, Relations->matrices Strings, polynomials->balls and bins