Motzkin Number Calculator

Compute exact Motzkin numbers from the lattice-path recurrence

Introduction to Motzkin Numbers

Motzkin numbers are a compact way to count several combinatorial structures that all turn out to be equivalent. In the lattice-path view, you start at (0,0) and move one step at a time using three allowed moves: an up step, a horizontal step, or a down step. Every valid path must end at height zero and must never dip below the horizontal axis. The number of such paths of length n is the Motzkin number M(n). The same sequence also counts non-crossing chord diagrams on a circle and a range of recursively defined trees and partitions.

This calculator returns the exact value of M(n) for any integer from 0 to 100, so it works both as a fast lookup tool and as a way to explore how the sequence behaves as n grows. Because Motzkin numbers expand quickly, the page uses JavaScript BigInt arithmetic to keep every answer exact instead of rounding large integers into floating-point approximations.

The first few Motzkin numbers are 1, 1, 2, 4, 9, 21, 51, 127, 323, 835, and so on. Even if the sequence is new to you, the pattern becomes much easier to understand when you think about how valid paths are built. A path can begin with a horizontal step and then continue with any smaller valid Motzkin path, or it can begin with an up step that is eventually matched by a down step, enclosing two smaller subproblems. That decomposition is the reason the recurrence works.

How to Use the Motzkin Number Calculator

Using this Motzkin number calculator is simple: enter a whole number n in the input field, then press Calculate M(n). The results panel will show the input value n, the Motzkin number M(n), and a growth ratio that compares M(n) with the previous term M(n−1) when that comparison makes sense.

There is no physical unit attached to the input because Motzkin numbers are pure counts. In this setting, n is both the sequence index and the length of the corresponding lattice path. For instance, if you enter 3, the calculator counts every valid path of length 3 that stays on or above the axis and finishes back at height zero.

If the answer is very long, the display trims it for readability and adds a digit count so you still know how large the exact value is. The copy button still copies the full result in the form M(n) = value, which is handy if you want to paste the answer into notes, homework, a spreadsheet, or your own program.

For best results, stick with nonnegative integers. The form already limits entries to 0 through 100, which is a practical browser-friendly range for exact Motzkin counts. That range is large enough to reveal the sequence's growth while still being fast to compute on ordinary devices.

Motzkin Number Recurrence Formula

The Motzkin recurrence used by this calculator is the standard counting relation, and the MathML below shows the same structure in symbolic form:

M ( n ) = M ( n 1 ) + k=0 n2 M ( k ) · M ( n 2 k )

The starting values are M(0) = 1 and M(1) = 1. In words, every valid Motzkin path of length n lands in one of two categories. It either starts with a horizontal step, leaving a valid path of length n−1, or it starts with an up step that is eventually matched by a down step. The area inside that matched pair contributes one smaller Motzkin path, and the remaining steps outside the pair contribute another. Adding up every possible split point gives the summation term.

That same structure is why dynamic programming is such a good fit here. Rather than recomputing the same smaller values over and over, the script builds the Motzkin sequence from the bottom up. For a calculator page, that approach is much faster and far more dependable than trying to expand the recurrence recursively each time you submit a new index.

Worked Example: Computing M(3) with Motzkin Paths

To make the Motzkin recurrence concrete, let's compute M(3) step by step. This is a good size for a worked example because it is small enough to inspect by hand, yet it still shows both parts of the recurrence.

Start with the formula for M(3):

M(3) = M(2) + [M(0)·M(1) + M(1)·M(0)]

Now evaluate the smaller term first:

M(2) = M(1) + M(0)·M(0) = 1 + 1 = 2

Substitute that value back into the expression for M(3):

M(3) = 2 + (1·1 + 1·1) = 2 + 2 = 4

You can check the answer directly by listing the four valid paths of length 3: HHH, UDH, UHD, and HUD. This tiny example is useful because it shows how the recurrence and the path model describe the same count from different angles. The recurrence gives you a compact computational rule, while the path picture explains what the count is actually measuring.

What the Motzkin Result Means

When the calculator returns M(n), it is giving the exact number of Motzkin structures of size n. If you are thinking in terms of lattice paths, that result is the count of all legal paths with n steps. If you are thinking in terms of non-crossing chords, it is the number of admissible chord configurations on the matching number of points. The same integer therefore answers several different combinatorial questions at once.

The growth ratio shown in the results area is not a separate theorem; it is simply the numerical quotient M(n) / M(n−1). It gives you a quick way to see how the Motzkin sequence expands as n increases. For small values the ratio moves around noticeably, but as n grows it starts to reflect the sequence's overall growth behavior. That makes it a handy snapshot of how fast the counts are increasing.

Because the displayed value may be shortened when it contains many digits, remember that the underlying Motzkin calculation is still exact. The truncation is only there to keep the page readable. If you need the full integer, use the copy button or reproduce the same recurrence in your own code.

Motzkin Number Applications and Assumptions

Motzkin numbers appear in discrete mathematics, formal language theory, graph theory, and even some counting problems in computational biology. They are often introduced as a bridge between Catalan-style counting and richer path models that allow a neutral horizontal move. That extra move makes Motzkin numbers a natural fit for processes that can rise, fall, or stay level while still respecting a nonnegativity constraint.

This calculator assumes the standard unweighted Motzkin model. Every allowed step contributes equally, paths are not allowed to go below the axis, and the path must end at height zero after exactly n steps. If your problem uses weighted steps, colored steps, restricted plateaus, or modular arithmetic, then you are working with a variant rather than the basic sequence shown here.

It is also worth noting what this calculator does not do. It does not list every Motzkin path, draw all chord diagrams, or solve generalized enumeration problems automatically. Its purpose is to compute the count efficiently and explain the meaning of that count. For classroom use, puzzle checking, and algorithm-analysis tasks, that exact count is often the only number you need.

Finally, Motzkin numbers are a good reminder that a single integer sequence can connect several areas of mathematics. A recurrence, a path model, and a geometric non-crossing interpretation all lead to the same values. That kind of equivalence is one of the reasons combinatorics is so useful: it lets you translate a difficult-looking problem into a form that is easier to reason about or compute.

Motzkin Sequence Reference

This quick reference table gives a few benchmark Motzkin values so you can compare your result with known terms in the sequence. The growth ratio column is especially helpful when you want a rough sense of how quickly the numbers accelerate.

n M(n) Growth Ratio Properties
0 1 Base case
1 1 1.00 Single horizontal step
3 4 2.00 Four distinct paths
5 21 2.33 Rapid growth begins
10 835 2.54 Exponential growth
15 310,235 2.60 Growth approaches about 2.62^n

Calculator

Calculate Motzkin Number
Enter an integer from 0 to 100.

Motzkin Path Mini-Game

This optional arcade mini-game turns the same Motzkin-path idea behind the calculator into a fast reflex challenge. You guide a glowing path-builder across a scrolling grid and try to collect legal Motzkin steps in order: horizontal steps are always safe, up steps raise your height, and down steps are only safe when they do not send you below the axis. The goal is to build as many valid partial Motzkin paths as possible before time runs out. It is separate from the calculator, so playing it will not change your computed result.

0Score
45.0Time
0Streak
0Height

Start game

Click to play. Move your cursor or finger to steer the path token. Collect glowing H, U, and D gates. Horizontal gates are always valid. Up gates increase height. Down gates score only when your current height is above zero, because a Motzkin path cannot go below the axis.

Build streaks for bonus points, survive the full timer, and keep your height balanced. Desktop players can also use the arrow keys or A/D keys to drift left and right.

Embed this calculator

Copy and paste the HTML below to add the Motzkin Number Calculator | Exact Sequence Values to your website.