tinycodinglm / math /math-0154.jsonl
winapiadmin's picture
Upload folder using huggingface_hub (part 15)
b27bfb3 verified
|
Raw History Blame
896 Bytes
opencode trace
System You are an expert mathematician and programmer.

You are an expert mathematician and programmer.

User

Explain Catalan numbers applications

Assistant

C_n = C(2n,n)/(n+1) = sum(C_i * C_{n-1-i}) for i=0..n-1.
First: 1,1,2,5,14,42,132,429,1430.

Applications (all count same thing):

  1. Balanced parentheses: n pairs in valid order
  2. BST shapes: n distinct keys
  3. Triangulations: convex (n+2)-gon
  4. Dyck paths: (0,0) to (2n,0) staying above x-axis
  5. Non-crossing partitions of n elements
  6. Full binary trees with n+1 leaves
  7. Stack-sortable permutations

Mod prime: C(2n,n) * mod_inverse(n+1) mod p.
Generalization: Fuss-Catalan C_n^(m) = C(mn,n)/(mn-n+1).