Catalan numbers: Difference between revisions

Content added Content deleted
(Added APL)
m (shown the formulas in larger fonts to be easier to read the italics and subscripts, add a Task (bold) header.)
Line 1: Line 1:
{{wikipedia}}{{task|Arithmetic operations}}Catalan numbers are a sequence of numbers which can be defined directly:
{{wikipedia}}{{task|Arithmetic operations}}

:<math>C_n = \frac{1}{n+1}{2n\choose n} = \frac{(2n)!}{(n+1)!\,n!} \qquad\mbox{ for }n\ge 0.</math>
<br>
Catalan numbers are a sequence of numbers which can be defined directly:

<big><big>
::: <math> C_n = \frac{1}{n+1}{2n\choose n} = \frac{(2n)!}{(n+1)!\,n!} \qquad\mbox{ for }n\ge 0 </math>
</big></big>
Or recursively:
Or recursively:
<big><big>
:<math>C_0 = 1 \quad \mbox{and} \quad C_{n+1}=\sum_{i=0}^{n}C_i\,C_{n-i}\quad\text{for }n\ge 0;</math>
::: <math> C_0 = 1 \quad \mbox{and} \quad C_{n+1}=\sum_{i=0}^{n}C_i\,C_{n-i}\quad\text{for }n\ge 0 </math>
</big></big>
Or alternatively (also recursive):
Or alternatively (also recursive):
<big><big>
:<math>C_0 = 1 \quad \mbox{and} \quad C_n=\frac{2(2n-1)}{n+1}C_{n-1},</math>
::: <math> C_0 = 1 \quad \mbox{and} \quad C_n=\frac{2(2n-1)}{n+1}C_{n-1} </math>
</big></big>


;Task:
Implement at least one of these algorithms and print out the first 15 Catalan numbers with each.

[[Memoization]] &nbsp; is not required, but may be worth the effort when using the second method above.


Implement at least one of these algorithms and print out the first 15 Catalan numbers with each. [[Memoization]] is not required, but may be worth the effort when using the second method above.


Related tasks:
;Related tasks:
*[[Catalan numbers/Pascal's triangle]]
*[[Catalan numbers/Pascal's triangle]]
*[[Evaluate binomial coefficients]]
*[[Evaluate binomial coefficients]]
<br><br>


=={{header|360 Assembly}}==
=={{header|360 Assembly}}==