Mathematics for Computer Science MIT 6.042J/18.062J Combinatorics I Copyright © Radhika Nagpal, 2002. Prof. Albert Meyer & Dr. Radhika Nagpal
Counting Techniques Bijections Sum Rule, Inclusion-Exclusion Product Rule Pigeonhole Principle Trees Permutations
Counting Strings How many strings of length 3 can make with the alphabet A = {r,a,d} ?
Counting Strings (3) (3) (3) {r,a,d} {r,a,d} {r,a,d} (3) (3) (3) {r,a,d} {r,a,d} {r,a,d} Number of strings = 3.3.3 = 27
Counting Rearrangements How many strings of length 3 can I make by rearranging the letters rad?
Permutations (3) (2) (1) {r,a,d} {?,?} {?} (3) (2) (1) {r,a,d} {?,?} {?} Number of strings, |S| = 3.2.1 = 6
Permutations (3) (2) (1) {r,a,d} {?,?} {?} S = {rad, rda ard, adr (3) (2) (1) {r,a,d} {?,?} {?} S = {rad, rda ard, adr dra, dar}
Permutation Tree d rad rda ard adr dra dar a a d d r r a d r d r a a r
… … Strings Tree r a d r r a a d d r r a a d d rrr rra rrd rar raa rad rda rdd ….. drr dra drd dar daa dad ddr dda ddd a d r r a a d d r r … a a d … d
Comparison rearrangement strings n n2 n! nn 1 1 1 1 5 25 120 3125 1 1 1 1 5 25 120 3125 10 100 ~107 1010 400 ~1018 1026 40 1600 ~1047 1064 100 10000 ~10157 10200 1000 106 scheme dies…..
Important technique: Matching Make a one-to-one 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
Counting Functions f B A How many different possible functions are there from A to B? f b1 b2 b3 b4 b5 b6 a1 a2 a3 a4 a5 A B
Mapping: Functions as Strings a1 a2 a3 a4 a5 A B b1 b1 b1 b1 b1 b1 b2 b3 b1 b4 …… string of length 5 from the alphabet {b1, b2…b6} f
Counting Functions A B (6) (6) (6) (6) (6) a1 a2 a3 a4 a5 A B (6) (6) (6) (6) (6) Total number of possible functions = total number of possible strings = 6.6.6.6.6 =
Counting Bijections f B A How many different possible bijections are there from A to B? f a1 a2 a3 a4 a5 b1 b2 b3 b4 b5 A B
Counting Bijections A B Permutations of the letters {b1,b2,b3,b4,b5} a1 a2 a3 a4 a5 A B b1 b2 b3 b4 b5 b5 b4 b3 b2 b1 …… Permutations of the letters {b1,b2,b3,b4,b5}
Counting Bijections A B (5) (4) (3) (2) (1) a1 a2 a3 a4 a5 A B (5) (4) (3) (2) (1) Total number of possible functions = total number of possible permutations = 5.4.3.2.1 = 5!
Counting Graphs v1 v1 v1 v2 v3 v2 v3 v2 v3 How many possible directed graphs are there on n nodes? v1 v1 v1 v2 v3 v2 v3 v2 v3
Graphs as Binary Strings Maximum possible edges = n2 e1 e2 e3 …… en2 G1 1 0 1 0 ….. 1 G2 0 1 1 0……1 G3 ..
Graphs as Boolean Matrices 1 0 1 0 1 1 2 3 . n Any assignment of 1s and 0s is a possible graph
Proving that a Mapping is a Bijection Prove that g: F S is a bijection Prove that all elements in F map to a unique elements of S Prove that all elements in S map to some F
Example: Graph Isomorphism G1 and G2 are isomorphic if there is a bijection f from the nodes of G1 to the nodes of G2, that preserve the adjacency lists. Question: At most how many functions do I need to check to determine whether or not G1 and G2 are isomorphic? Answer: All possible bijections from the nodes of G1 to G2 = n!
In-class Problems