Motzkin Number Calculator
Count the paths that never dip below the axis using up, level and down steps, with the previous value shown.
What it does
A Motzkin path of length n starts at height zero, ends at height zero and never goes below zero. It uses three kinds of steps: up one, level zero and down one. The Motzkin number M(n) counts how many such paths exist. For n = 5 the answer is 21.
The sequence is named after Theodore Motzkin, a mathematician who worked on combinatorial geometry. The same numbers count the ways to draw noncrossing chords between points on a circle, with some points left unpaired, which is why they appear in problems about RNA folding and matching parentheses with gaps.
The recurrence used here has a clear picture behind it. A path either begins with a level step, leaving a shorter path of length n minus one, or begins with an up step, later returns to the axis, and splits into two independent paths on either side of that first return. Summing over the possible positions of the return gives the formula.
This page evaluates that recurrence with exact integers, starting from M(0) = 1. It reports M(n), the previous value and the ratio between them. The growth is slower than the Catalan numbers because level steps give the path more freedom without forcing a paired step.
The index limit is 100. That produces a large integer which is printed in full, with no rounding at any step. The tool gives counts only and does not draw or list individual paths.
How to use
- Enter an index n from 0 to 100.
- Read M(n) from the main result box.
- Check the previous value and the growth beside it.
- The default n = 5 reproduces the worked example.
- Try n = 9 to confirm the value 835.
- Compare with a Catalan count to see how level steps change the total.
Formula
- n
- The length of the path in steps.
- M(j)
- A shorter Motzkin number used in the sum.
- M(n)
- The total number of valid paths of length n.
The first term covers a level step at the start. The sum covers an up step paired with its first return to the axis, leaving j steps inside the excursion and n minus two minus j steps after it. The empty path has length zero and counts once, so M(0) = 1.
Worked example
Example: M(5)
The page opens with n = 5.
- List the earlier values: M(0) = 1, M(1) = 1, M(2) = 2, M(3) = 4 and M(4) = 9.
- The level step case contributes M(4) = 9.
- The paired step case sums j from 0 to 3.
- Compute the products: M(0)M(3) = 4, M(1)M(2) = 2, M(2)M(1) = 2 and M(3)M(0) = 4.
- Add the products: 4 + 2 + 2 + 4 = 12.
- Add the level case: 9 + 12 = 21.
- The tool reports 21, previous value 9, and growth 2.33x.
Reference table
| n | M(n) | Previous | Growth |
|---|---|---|---|
| 0 | 1 | n/a | n/a |
| 1 | 1 | 1 | 1.00x |
| 2 | 2 | 1 | 2.00x |
| 3 | 4 | 2 | 2.00x |
| 4 | 9 | 4 | 2.25x |
| 5 | 21 | 9 | 2.33x |
| 9 | 835 | 323 | 2.59x |
Limits
- Paths must return to height zero and stay nonnegative.
- Only the three step types of length one are allowed.
- Indices above 100 are rejected to keep the printed integer short.
- The tool gives counts and does not list or draw the paths.
Common mistakes
- Leaving out the level step case at the start of the recurrence.
- Using j up to n minus one instead of n minus two in the sum.
- Allowing paths to dip below the horizontal axis.
- Confusing Motzkin paths with Dyck paths, which have no level steps.
- Counting crossing chord drawings as distinct from noncrossing ones.
Try it yourself
Quick checks. Answers sit tucked under each question.
What is M(9)?
M(9) = 835, with M(8) = 323 before it and a growth of 2.59.
What is M(5)?
M(5) = M(4) + 4 + 2 + 2 + 4 = 9 + 12 = 21.
What is M(0)?
M(0) = 1, the single empty path of length zero.
Questions
What is a Motzkin path?
A walk from height zero back to zero using up, level and down steps that never goes below the starting level.
How does this differ from Catalan numbers?
Catalan paths have only up and down steps, while Motzkin paths also allow level steps.
What else do these numbers count?
Ways to join points on a circle with noncrossing chords, with some points left free.
Why is M(4) equal to nine?
Four level steps give one path, and the remaining arrangements with one or two up steps bring the total to nine.
Are the values exact?
Yes. The recurrence uses only integer multiplication and addition.
What is the largest index?
One hundred, with a readable error for larger inputs.