input: Write a python function to calculate the number of binary search trees (BST) for a given number of nodes 'n'.
  assert num_bst(0) == 1
  assert num_bst(1) == 1
  assert num_bst(3) == 5
  assert num_bst(5) == 42
output: def num_bst(n):
      if n == 0 or n == 1:
          return 1
      catalan = [0] * (n + 1)
      catalan[0], catalan[1] = 1, 1
      for i in range(2, n + 1):
          for j in range(i):
              catalan[i] += catalan[j] * catalan[i - j - 1]
      return catalan[n]