catalan

catalan(n)

Try it yourself:


catalan(): count recursive structures

catalan(n) returns the nth Catalan number. This sequence begins 1, 1, 2, 5, 14, 42 and counts many apparently different structures: correctly nested parentheses, binary search tree shapes, polygon triangulations, and non-crossing pairings.

Formula and example

For a non-negative integer n, the value is binomial(2n, n)/(n + 1). catalan(3) is 5, which is the number of valid ways to arrange three matched pairs of parentheses. The numbers grow quickly, so exact integer arithmetic is preferable for larger n.

Related combinatorics

combinations() computes the central coefficient in the formula. For other counting families, see combinations(), bernoulli(), and stirlingS2(). factorial() helps derive the equivalent factorial form.

Valid input

n must be a non-negative integer. A fractional or negative index does not identify a standard Catalan number. Do not confuse a count of structures with a probability; normalize separately if needed.

Try Catalan in Calcul.io

Start with one of the editable examples above, then replace its arguments with your own values. Keeping the function on a separate calculator line makes the input and result easy to compare. For a longer workflow, assign the result to a variable or reference that line in the next expression.

Check the shown signature before adding optional arguments, and use the related-function links to compare operations with similar purposes.

All functions