Skip to main content
๐Ÿ“œ WAYPOINT LESSON

Catalan Numbers

โญโญโญ advancedโณ 30 min read๐Ÿ“ Lesson 173 of 281

When counting structures whose every prefix is 'balanced', the answer is a Catalan number โ€” C(2n,n) - C(2n,n+1).

Counting balanced structures

Balanced brackets, binary trees, triangulations, non-crossing pairings: one sequence, C_n = C(2n,n) - C(2n,n+1). The subtraction removes the structures whose running balance dips negative โ€” a bijection to unrestricted paths ending one step off. Precompute factorials once; each query is O(1).