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 algorithms work on them recurrence relation an = an  an = n an = 2an  an = 2n an = nan  an = n!

6 Binomial Coefficient nCk - 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 (a + b)3 = aaa + 3aab + 3abb + bbb think the other way what is the coeff of akbn-k ? how many ways to choose k a-terms out of n

8 Pascal’s Triangle 4C3 = 3C2 + 3C3 4C0 4C1 4C2 4C3 4C4
Sum=2n 1 2 4 8 16 32 n=0 n=1 n=2 n=3 n=4 n=5 4C3 = 3C2 + 3C3 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! can 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 review Stirling Numbers, Partitions 0..9 <0..8> 에 9를 넣을 수 있는 위치는 마지막 위치만 가능 > k=3 9를 추가해서 k=4로 만들 수 있는 경우의 수는?

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