Skip to content
Liu Zhidong edited this page Mar 29, 2016 · 2 revisions

About catalan numbers, here is the explanation.

The array of the number is: 1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786....

For the python code it will be as:

def catnumber(n):
  ans = 1.0
  for k in range(2,n+1):
     ans = ans *(n+k)/k
  return ans

There are many counting problems in combinatorics whose solution is given by catalan numbers.

Image, the possibility of push or pop an array of number into a stack. Or, add the parentheses to get the possible results

[UniqueBinarySearchTrees] (https://github.com/allencharp/LeetCode/blob/master/UniqueBinarySearchTrees.py)

DifferentWaystoAddParentheses

Clone this wiki locally