Challenge: The Catalan Numbers
In this lesson, you will solve your first coding challenge using bottom-up dynamic programming.
We'll cover the following
Problem statement
The Catalan numbers are a special sequence of numbers given by the following set of formulas:
The first expression gives the base case of the formula. The second expression says that the Catalan number is simply the sum of products of specific Catalan number pairs. These specific pairs are just Catalan numbers with the same distance from either end of the series.
for example would be equal to:
You can already see the hefty amount of recursion in this series.
The Catalan numbers form the following series: (1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862…)
Applications of the Catalan numbers
The Catalan numbers readily appear in many interesting counting problems.
-
The number of ways to put parentheses around n numbers for multiplication.
-
The number of paths to climb up a 2n x 2n grid without going above the diagonal.
-
The number of possible binary trees with n leaf nodes. This has been shown in the visualization below.
Get hands-on with 1400+ tech skills courses.