Skip to Content
Combinatorics

2. Generating Functions

2019-09-04Original-language archivelegacy assets may be incomplete
  • ordinary generating function(OGF) define by ana_n: G(x)=n0anxnG(x)=\sum_{n\geq0}a_nx^n
  • coefficient: [xk]G(x)[x^k]G(x)
  • C[[x]]\mathbb{C}[[x]]: ring of formal power series with complex coefficient
  • Combination: 3 red, 4 blue, and 5 green
    • (1+x+x2+x3)(1+x+x2+x3+x4)(1+x+x2+x3+x4+x5)(1+x+x^2+x^3)(1+x+x^2+x^3+x^4)(1+x+x^2+x^3+x^4+x^5)
    • coefficient xkx^k gives the number of way to select kk balls
  • Fibonacci number
    • Fn=15(ϕnϕ^n),ϕ=1+52,ϕ^=152F_n=\frac{1}{\sqrt{5}}(\phi^n-\hat\phi^n),\phi=\frac{1+\sqrt{5}}{2},\hat\phi=\frac{1-\sqrt{5}}{2}
    • G(x)=x1xx2=x(1ϕx)(1ϕ^x)=α1ϕx+β1ϕ^xG(x)=\frac{x}{1-x-x^2}=\frac{x}{(1-\phi x)(1-\hat\phi x)}=\frac{\alpha}{1-\phi x}+\frac{\beta}{1-\hat\phi x}
  • General Methodology
    • Give a recursion that computes ana_n
    • Give the generating function and manipulate the right hand side of equation so that it becomes some other expression involving G(x)G(x)
      • shift: xkG(x)=nkgnkxnx^kG(x)=\sum_{n\geq k}g_{n-k}x^n
      • addition: F(x)+G(x)=n0(fn+gn)xnF(x)+G(x)=\sum_{n\geq 0}(f_n+g_n)x^n
      • convolution: F(x)G(X)=n0k=0nfkgnkxnF(x)G(X)=\sum_{n\geq 0}\sum_{k=0}^nf_kg_{n-k}x^n
      • differentiation: G(x)=n0(n+1)gn+1xnG'(x)=\sum_{n\geq0}(n+1)g_{n+1}x^n
    • Solve the resulting equation to derive an explicit formula for G(x)G(x)
    • Expand G(x)G(x) into a power series and read off the coefficient of xnx^n
      • Taylor expansion: G(x)=n0G(n)(0)n!xnG(x)=\sum_{n\geq 0}\frac{G^{(n)}(0)}{n!}x^n
      • Geometric sequence: 11x=n0xn\frac{1}{1-x}=\sum_{n\geq0}x^n
        • G(x)=i=1kai1bixG(x)=\sum_{i=1}^{k}\frac{a_i}{1-b_ix}, [xn]G(x)=i=1kaibin[x^n]G(x)=\sum_{i=1}^ka_ib_i^n
      • Newton's formular: (1+x)α=n0(αn)xn(1+x)^\alpha=\sum_{n\geq0}{\alpha\choose n}x^n
        • (αn)=α(α1)(α(n1))n!{\alpha\choose n}=\frac{\alpha(\alpha-1)\cdots(\alpha-(n-1))}{n!}
        • (nm)=(1)m(n+m1m){-n\choose m}=(-1)^m{n+m-1\choose m}
  • Catalan Number: Cn=k=0n1CkCn1k,C0=1C_n=\sum_{k=0}^{n-1}C_kC_{n-1-k},C_0=1
    • Interpretation
      • 出入栈:the number of expressions containing n pairs of parentheses which are correctly matched:以最后一个左括号的对应右括号的位置为 choice,划分成两个部分
      • Dyck words of length 2n2n(A Dyck word is a string consisting of n X's and n Y's such that no initial segment of the string has more Y's than X's)
      • the number of different ways n+1n + 1 factors can be completely parenthesized
      • the number of full binary trees with n+1n + 1 leaves
      • 单调路径:the number of monotonic lattice paths along the edges of a grid with n×nn × n square cells, which do not pass above the diagonal
      • 三角形剖分:triangulations of a convex (n+2)(n+2)-gon
      • 二叉树种类
    • Cn=1n+1(2nn)C_n=\frac{1}{n+1}{2n\choose n}
      • Generating function
        • G(x)2=n0k=0nCkCnkxnG(x)^2=\sum_{n\geq0}\sum_{k=0}^nC_kC_{n-k}x^n
        • G(x)=1+xG(x)2G(x)=1(14x)122xG(x)=1+xG(x)^2\Rightarrow G(x)=\frac{1-(1-4x)^{\frac{1}{2}}}{2x}
          • 二次方程只有一解:limx0G(x)=C0\lim_{x\rightarrow0}G(x)=C_0
        • G(x)=2n0(12n+1)(4x)nG(x)=2\sum_{n\geq0}{\frac{1}{2}\choose n+1}(-4x)^n
      • Andre's reflection method: Cn=(2nn)(2nn+1)C_n={2n\choose n}-{2n\choose n+1}
      • bijective proof: split up the set of all monotonic paths into n+1n + 1 equally sized classes
    • Ω(4nn3/2)\Omega(\frac{4^n}{n^{3/2}})
  • Quicksort
    • Quicksort recursion: Tn=1nk=1n(n1+Tk1+Tnk)T_n=\frac{1}{n}\sum_{k=1}^n(n-1+T_{k-1}+T_{n-k})
    • n0nTnxn=n0n(n1)xn+2n0(k=0n1Tk)xn\sum_{n\geq0}nT_nx^n=\sum_{n\geq 0}n(n-1)x^n + 2\sum_{n\geq0}(\sum_{k=0}^{n-1}T_k)x^n
    • xG(x)=2x2(1x)3+2x1xG(x)xG'(x)=\frac{2x^2}{(1-x)^3}+\frac{2x}{1-x}G(x)
    • G(x)=2(1x)2ln11xG(x)=\frac{2}{(1-x)^2}\ln\frac{1}{1-x}
    • Tn=2(n+1)H(n)2nT_n=2(n+1)H(n)-2n