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}} |
{{wikipedia}}{{task|Arithmetic operations}} |
||
⚫ | |||
<br> |
|||
Catalan numbers are a sequence of numbers which can be defined directly: |
|||
<big><big> |
|||
⚫ | |||
</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> 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> C_0 = 1 \quad \mbox{and} \quad C_n=\frac{2(2n-1)}{n+1}C_{n-1} </math> |
||
</big></big> |
|||
;Task: |
|||
⚫ | |||
[[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}}== |