Catalan Number
calculator.
Count balanced brackets, mountain paths, binary trees and polygon cuts for any n.
- Digits
- 2
- C₆ ÷ C₅
- 3.1429
- Estimate is off by
- 23.033%
For n = 5 you can list them all by hand. Each step up in n multiplies the count by 2(2n + 1) ÷ (n + 2), here 3.1429, which creeps toward 4 but never reaches it.
How fast the numbers grow
Drag the point to change nThe digits of Cₙ grow almost in a straight line, about 0.6 more for each step in n, because the terms grow like 4ⁿ. The dotted line is the estimate 4ⁿ ÷ (n^1.5 √π), which runs a little high and closes in as n grows. At n = 5 the estimate is off by 23.033%.
Find n for a value
The largest Catalan number not above it is C₃₅ = 3,116,285,494,907,301,262. The next one, C₃₆ = 11,959,798,385,860,453,492, is too big.
Working
- 1Closed form: the middle of row 2n of Pascal’s triangle, over n + 1C₅ =C(10, 5)6=2526= 42
- 2Segner’s recurrence: split at the first closing bracket, 5 terms1 × 14 + 1 × 5 + 2 × 2 + 5 × 1 + 14 × 1 = 42
- 3Check: all paths minus the ones that dip below the lineC(10, 5) − C(10, 6) = 252 − 210 = 42
The first 14 of 42 paths
Read ( as a step up and ) as a step down. A string is balanced exactly when its path never dips below the line.
C₀ to C₁₅
| n | Cₙ | Next ÷ this |
|---|---|---|
| 0 | 1 | 1 |
| 1 | 1 | 2 |
| 2 | 2 | 2.5 |
| 3 | 5 | 2.8 |
| 4 | 14 | 3 |
| 5 | 42 | 3.1429 |
| 6 | 132 | 3.25 |
| 7 | 429 | 3.3333 |
| 8 | 1,430 | 3.4 |
| 9 | 4,862 | 3.4545 |
| 10 | 16,796 | 3.5 |
| 11 | 58,786 | 3.5385 |
| 12 | 208,012 | 3.5714 |
| 13 | 742,900 | 3.6 |
| 14 | 2,674,440 | 3.625 |
| 15 | 9,694,845 | 3.6471 |
How it's worked out
The Catalan numbers start 1, 1, 2, 5, 14, 42, 132, and the term for n is written . OEIS A000108 gives the closed form. The top, a binomial coefficient, is the middle entry of row 2n of Pascal's triangle.
Segner's recurrence builds each term from smaller ones. Take a balanced string of brackets and find where the first bracket closes. Inside it is a balanced string of k pairs, and after it is one of n − 1 − k pairs. Add up the products over every k. For n = 5 that gives 1 × 14 + 1 × 5 + 2 × 2 + 5 × 1 + 14 × 1 = 42.
The page itself uses a faster step from one term to the next, one multiply and one exact divide each time. That is how it reaches n = 1,000 with every digit.
The check uses paths. A path of n up-steps and n down-steps can be chosen in ways. A reflection trick shows that of them dip below the start. Take those away, and what is left is . For n = 5 that is 252 − 210 = 42.
For large n the terms grow close to divided by . This estimate runs a little high. At n = 10 it is 11.38% over, and at n = 100 it is 1.13% over.
Worked examples
Sam lists every way to close three pairs of brackets
Sam is writing a test for a bracket checker and wants every valid input with three pairs. There are of them: ((())), (()()), (())(), ()(()), ()()().
The closed form agrees. The middle of row 6 of Pascal's triangle is 20, and 20 over 4 is 5. Of the 20 strings with three of each bracket, 15 close a bracket too early, which leaves 5.
Ana cuts a hexagon into triangles
A hexagon has 6 sides, which is n + 2 with n = 4, so Ana needs . Each way uses 3 diagonals and makes 4 triangles. There are 14 ways.
To see the recurrence, she fixes one edge. The triangle on that edge splits what is left into two smaller polygons, and that gives 1 × 5 + 1 × 2 + 2 × 1 + 5 × 1 = 14. Euler worked on this count in 1751, in a letter to Goldbach.
Kenji finds the last Catalan number a 64-bit integer holds
Kenji's program counts binary trees with a signed 64-bit integer, whose top value is 9,223,372,036,854,775,807. The largest Catalan number at or below that is = 3,116,285,494,907,301,262.
The next term, = 11,959,798,385,860,453,492, overflows. With 32-bit integers the limit comes much sooner, at = 1,767,263,190. So for n past 35 he switches to BigInt.
Reading your result
Four readings of one number. The same counts four things. It counts strings of n balanced bracket pairs. It counts mountain paths of n up-steps and n down-steps that stay at or above the start. It counts binary trees with n nodes, where each node has a left and a right branch that may be empty. And it counts ways to cut a polygon with n + 2 sides into triangles. Stanley's book on the subject lists 214 such readings.
Brackets and paths are the same thing. Read an open bracket as a step up and a close bracket as a step down. A string is balanced exactly when its path never dips below the line. For a tree, the part inside the first pair of brackets is the left branch, and the rest is the right branch.
The ratio to the next term is 2(2n + 1) over n + 2. It climbs toward 4 but never reaches it, so each term is a bit less than four times the one before. That is why already has 57 digits and has 598.
Common mistakes
- Using n for the number of sides. A polygon with n sides has cuts, not . A hexagon gives , not .
- Mixing up pairs and letters. Putting brackets into a product of n + 1 letters, such as abcd for n = 3, also gives . So 4 letters give 5 ways, not 14.
- Working out the factorials in full. overflows a 64-bit integer long before does, since still fits. The step from one term to the next keeps every value close to the answer's size.
- Using it for unequal vote counts. answers the ballot problem only when both sides get n votes. With unequal counts you need the general ballot numbers, which this page does not compute.