Formula: Catalan Numbers (C_n) Formula
- catalanIndexN: Catalan Index N (n)
Compute the n-th Catalan number C_n, asymptotic growth 4^n / (n^(3/2)√π), and recurrence ratio.
There is exactly one way to arrange zero pairs of brackets: the empty string, which is trivially balanced. Likewise there is one empty Dyck path and one tree with no internal nodes. The formula agrees, since C(0, 0) / 1 is 1. Starting the sequence at 1 also makes the sum recurrence work for every n.
Catalan numbers only exist for whole indices, because each counts whole objects such as n pairs of brackets. The page therefore shows an input error for decimals instead of rounding them. Type 3 for C_3 = 5 or 4 for C_4 = 14. The same error appears for negative values and for anything above 25.
Twenty-five. Larger values show an input error, because beyond that point the numbers exceed the range where the engine's arithmetic stays exact. C_25 is already about 4.9 trillion. For larger indices, use software with arbitrary precision integers and the ratio recurrence, which only ever multiplies and divides whole numbers.
Both statements appear in textbooks, and they describe the same count from different angles. C_n is the number of binary trees with n nodes, where each node may have a left child, a right child, both or neither. It is also the number of full binary trees with n + 1 leaves, where every internal node has exactly two children.
A convex polygon with n + 2 sides has C_n triangulations, so a decagon, with ten sides, corresponds to n = 8. Enter 8 in the index box to read the value. For an octagon use n = 6, which gives the default 132, and for a hexagon use n = 4, which gives 14.
The ratio equals 4 minus 6 / (n + 2), and that second term is always positive. It gets smaller as n grows, so the ratio climbs towards 4 but never reaches it. At the default n = 6 the ratio is 3.25, and at n = 10 it is 3.5, still clearly short of the limit.
Only indirectly. With k types of bracket that must each match correctly, the count is C_n x k^n, because the nesting shape is a Catalan structure and each pair can be any of the k types independently. Read C_n from the page and multiply by k raised to the power n yourself.
They should, across the whole accepted range of 0 to 25. The Catalan number is computed from the central binomial coefficient and divided by n + 1, which always gives a whole number. A quick check: C_10 = 16,796 and C(20, 10) = 184,756, and dividing the second by 11 gives the first exactly.
Compute the first few answers by hand. If they run 1, 2, 5, 14, the odds are high. Better still, see whether each object splits at a first natural break into an inner and an outer part of the same kind. That structure produces the sum recurrence, which only Catalan numbers satisfy with C_0 = 1.
Paths of length 2n that stay strictly above ground except at the start and end are counted by C_{n-1}. Lift the first and last steps away and what remains is an ordinary Dyck path of length 2n minus 2. So for n = 7 you would read the default C_6 = 132 from the page.
Yes, but rarely. C_n is odd exactly when n is one less than a power of two, so C_0, C_1, C_3, C_7 and C_15 are odd and every other value in the page's range is even. You can see it in the outputs: C_3 = 5 and C_7 = 429 are odd, while C_6 = 132 and C_10 = 16,796 are even.
The default index is n = 6. The calculator reports C_6 = 132, with the central binomial coefficient C(12, 6) = 924 beside it and the next Catalan number, C_7 = 429, just below.
The closed formula is C_n = C(2n, n) / (n + 1). For n = 6 that is 924 divided by 7, which is exactly 132 with no remainder. The division always comes out whole, which is one of the small surprises of the sequence: the central binomial coefficient is always a multiple of n + 1.
The next value comes from the ratio formula on the page, C_{n+1} = 2(2n + 1) / (n + 2) x C_n. With n = 6 the multiplier is 26 / 8, which is 3.25, and 132 x 3.25 gives 429 exactly. That multiplier is the "Growth Ratio" line.
You can confirm both numbers from the start of the sequence: 1, 1, 2, 5, 14, 42, 132, 429 and onward. Each term is the one before it times the ratio for that step. Going from C_5 = 42 to C_6 = 132 uses a multiplier of 22 / 7, about 3.14, and going from C_4 = 14 to C_5 = 42 uses exactly 3.
The page lists several structures, and they are all counted by the same number for the same n. With n = 6, each of the following has exactly 132 members.
Balanced parentheses: strings of six opening and six closing brackets where no prefix has more closings than openings. Dyck paths: walks of twelve steps, each up or down, that start and finish at ground level and never go below it. Full binary trees with seven leaves, which is the same as binary trees with six internal nodes. Triangulations of a convex octagon, since a polygon with n + 2 sides has C_n triangulations. And the ways to fully parenthesise a product of seven factors, such as a x b x c x d x e x f x g, so that every multiplication is between exactly two things.
The match is not a coincidence. Each of these can be converted into any other by a simple rule. A Dyck path becomes a parenthesis string if you write an opening bracket for each up step and a closing bracket for each down step. A parenthesised product becomes a binary tree if each multiplication is a node and each factor is a leaf.
The small cases are easy to list. C_3 = 5 gives the five strings ((())), (()()), (())(), ()(()) and ()()(). C_4 = 14 is the number of ways to cut a hexagon into triangles with non-crossing diagonals.
Because the counts agree, a result proved for one structure transfers to all of them. If you can show that some new family of objects maps one to one onto Dyck paths, you immediately know its size for every n, and this page gives you the specific number.
C(12, 6) = 924 is the number of ways to arrange six up steps and six down steps in any order, with no restriction. Catalan numbers count the subset that never dip below the start.
The classic reflection argument shows exactly how many paths are lost. Take any path that does go below zero, find the first step where it does, and flip every step after that point. The flipped path ends two levels lower, and the flip can be reversed, so bad paths match one to one with unrestricted paths of seven downs and five ups. Subtracting those from 924 leaves 132, the Catalan count.
That gives a second formula, C_n = C(2n, n) minus C(2n, n + 1), which simplifies to the one on the page. It also explains why the fraction of good paths is 1 / (n + 1). At n = 6 one path in seven stays above ground. At n = 10, where the page shows C(20, 10) = 184,756 and C_10 = 16,796, it is one in eleven.
So the central binomial line is not decoration. It is the total population that the Catalan number is a share of, and the share shrinks steadily as n grows.
The growth ratio line is labelled as tending to 4.0, and running a few indices shows how slowly it gets there. At n = 2 it is 2.5. At n = 4 it is 3. At the default n = 6 it is 3.25, and at n = 10 it is 3.5.
The formula explains why. The ratio is 2(2n + 1) / (n + 2), which is 4 minus 6 / (n + 2). The shortfall from 4 is six divided by n + 2, so halving the gap needs roughly double the index. At the page's maximum of n = 25 the ratio is still only about 3.78.
This also lets you estimate how fast counts blow up. Each extra pair of brackets multiplies the number of valid strings by somewhat less than four. The n = 10 preset makes the point: C_10 is 16,796 and the next value, C_11, is 58,786, three and a half times larger from one extra pair.
The summary on the page mentions the asymptotic form 4^n / (n^(3/2) x square root of pi). That approximation overestimates small Catalan numbers. At n = 6 it comes out roughly a fifth too high, and the error shrinks roughly in proportion to 1 / n, so it is good for growth rates and rough sizes rather than exact counts.
The page shows the closed form and the ratio step, but most combinatorics problems reveal themselves through a different recurrence. C_0 = 1, and C_{n+1} is the sum of C_i x C_{n-i} for i from 0 to n.
It comes from splitting a structure at its first natural break. In a balanced string, the first opening bracket has a matching closing bracket. Whatever lies inside that pair is a balanced string of i pairs, and whatever follows it is a balanced string of n minus i pairs. Summing over every possible split gives the recurrence.
Check it against the defaults. C_7 should equal C_0 x C_6 + C_1 x C_5 + C_2 x C_4 + C_3 x C_3 + C_4 x C_2 + C_5 x C_1 + C_6 x C_0. That is 132 + 42 + 28 + 25 + 28 + 42 + 132, which adds up to 429 and matches the page.
When you meet a new counting problem and can break each object into a left part and a right part of the same kind, with sizes adding to one less than the whole, you are almost certainly looking at Catalan numbers. That test is often faster than guessing from the first few terms.
The index box only accepts whole numbers from 0 to 25. Anything else, a decimal such as 3.6, a negative value or 26 and above, produces an input error rather than a quietly adjusted answer. Catalan numbers are only defined for whole indices, so a decimal has no meaning here.
The three comparison presets sit inside that range on purpose. The n = 4 row gives C_4 = 14, with C(8, 4) = 70 and C_5 = 42, small enough to list every structure by hand. The default n = 6 gives 132 structures. The n = 10 row gives 16,796, with a central binomial of 184,756 and a next value of 58,786 for C_11.
The upper limit exists because the values grow past what ordinary floating point arithmetic can hold exactly. C_25 is already about 4.9 trillion, and the next value it reports, C_26, is close to the edge of exact whole-number arithmetic in a browser. Rather than show a figure that might be off by a few units, the page stops at 25.
At the bottom, n = 0 is allowed and gives C_0 = 1, the empty structure. It is a legitimate case, not an error, and it anchors the recurrence described above.
Catalan numbers turn up whenever you enumerate tree-shaped or nested objects, which makes them practical as well as pretty.
If an algorithm tries every binary search tree shape for n keys, it is visiting C_n shapes. For six keys that is 132, which is fine. For ten keys it is 16,796, and by twenty keys it is in the billions, which is why dynamic programming over subranges replaces brute force in problems like optimal binary search trees and matrix chain ordering.
In testing, the counts make good sanity checks. A generator meant to produce every valid bracket string of six pairs should yield exactly 132 distinct strings. If yours produces one string more or one fewer, there is a bug in the generator, and the page gives you the target in one step.
Puzzles use the same idea. Mountain range drawings, non-crossing handshakes among people seated at a round table, and stack-based sorting all lead to Catalan counts. Recognising the pattern tells you the answer for every size at once, and the calculator supplies the specific value.