Presentation is loading. Please wait.

Presentation is loading. Please wait.

Combinatorics.

Similar presentations


Presentation on theme: "Combinatorics."— Presentation transcript:

1 Combinatorics

2 Combinatorics is a branch of mathematics concerning the study of finite or countable discrete structures In the past, ad-hoc solutions were available. Now, ....

3 Counting Techniques product rule sum rule Inclusion-Exclusion Formula
5 shirts * 4 pants = total 20 combinations sum rule if any one is missing from the closet, it is one of 9 clothing pieces Inclusion-Exclusion Formula |A  B| = |A| + |B| - |A  B| |A  B  C | = |A| + |B| + |C| - |A  B| - |B  C| - |B  C| + |A  B  B | eliminates double counting Bijection map a member of a set to a member of target set that is to be counted

4 More counting techniques
Permutation an arrangement of n items where every item appears exactly once - n!=∏ni=1 i arrange three letters word using a, b, c abc, acb, bac, bca, cab, cba, - 6 words (3!) what if letters are reused? (strings) aaa, abb, n∏r= nr Subsets there are 2n subsets of n items a, b, c, ab, bc, ac, abc, and an empty set – 8 subsets

5 Recurrence Relations Recursively defined structures
tree, list, WFF, ... divide & conquer recursively recurrence relation an = an  an = n an = 2an  an = 2n an = nan  an = n! wff: a finite sequence of symbols from a given alphabet that is part of a formal language.

6 Binomial Coefficient the number of ways to choose k things out of n
easy one how many ways to form a k-member committee from n people Paths across a grid of n X m

7 Binomial Coefficient (2)
coefficient of (a+b)n (a + b)3 = 1a3 + 3a2b + 3ab2 + 1b3 think the other way what is the coeff of akbn-k ? (a + b)3 = aaa + 3aab + 3abb + bbb how many ways to choose k a-terms out of n

8 Pascal's Triangle 4C0 4C1 4C2 4C3 4C4 nCk = (n-1)C(k-1) + (n-1)Ck
Sum=2n 1 2 4 8 16 32 n=0 n=1 n=2 n=3 n=4 n=5 1a3 + 3a2b + 3ab2 + 1b3 Is this a coincidence? 4C0 4C1 4C2 4C3 4C4 nCk = (n-1)C(k-1) + (n-1)Ck

9 Binomial Coefficient(3)
k n-1 n case1: this is included same as choosing k-1 from n-1 case2: not must choose k from n-1 nCk = (n-1)C(k-1) + (n-1)Ck (n-k)!k! may cause overflow n k n! (n-k)!k! =

10 Stop the recurrence good ending points nCk = (n-1)C(k-1) + (n-1)Ck
nC1 = n nCn = 1

11 safeness time complexity what about 3C0, 2C5, (-3)C5
int bc(int n, int k) { if (k == 1) return(n); return bc(n-1, k-1) + bc(n-1, k); } nCk = (n-1)C(k-1) + (n-1)Ck safeness what about 3C0, 2C5, (-3)C5 don’t we need else part? time complexity one comparison and one addition (let it be C1) let recursion overhead be C2 T(n, k) = T(n-1, k-1) + T(n-1, k) + C1 + C2

12 Fibonacci Numbers F0 = 0 F1 = 1 Fn = Fn-1 + Fn-2 for n  2
int fb(int n) { if (n < 0) ???? if (n < 2)) return(n); // f(0) =0, f(1) = 1 else return fb(n-1) + fb(n-2); }

13 Eulerian Numbers the number of permutations of the numbers 1 to n in which exactly k elements are greater than the previous element 0..9, k=3 case 1: add 9 on sol of 0..8 k=3 w/o changing k case 2: add 9 on sol of 0..8 k=2 increasing k case 3: add 9 on sol of 0..8 k=1 impossible exercise on Stirling Numbers 0..9 <0..8> 에 9를 넣을 수 있는 위치는 k( 두 수 사이, 나머지는 k 값 증가) > k=3 x x x k 값 불변 9를 추가해서 k=2에서 3으로 만들 수 있는 경우의 수는? 두 곳 말고 거의 모든 곳에서 k값 1 증가 k=1 에서 k=3 이 되는 경우는? 없음

14 Induction prove/disprove that Tn=2n-1 n … Tn Tn = 2Tn-1 + 1, T0=0 1 2
1 2 3 4 5 6 7 Tn 15 31 63 127 prove/disprove that Tn=2n-1

15 How Many Pieces of Land Let P(n) be the number of lands when n points are drawn on circle  Now assume knowing P(n-1), want to know P(n) by adding the n-th point  when the n-th point draw a line to the k-th point (1 <= k <= n-1)  on the LHS on k-th point, there is k-1 points between k-th and n-th point  on the RHS on k-th point, there is (n-1)-k+1 points between k-th and n-th point  the points in these 2 sets(LHS, RHS) are completely connected,  so there are (k-1)*(n-k) lines crossed by the newly drawn line,  creating (k-1)*(n-k)+1 new lands......  So, drawing lines from newly added n-th point to all n-1 old points,  will create  summation[(k-1)(j-k)+1] {k = 1..j (j = n-1)} new lands  let says the summation be F(j)  P(n)= P(n-1) + F(n-1)  = P(n-2) + F(n-2) + F(n-1)  .....  = P(0) + F(1) + F(2) F(n-1)  = 1 + summation(F(i)) {i = 1..n-1}  by using formula of summation to simplify the equatoin(what a difficult job.....)  I get  answer = (i - 1) * i * (i * i - 5 * i + 18) / ; 

16 Tower of Hanoi


Download ppt "Combinatorics."

Similar presentations


Ads by Google