Motzkin Number Calculator

Calculate Motzkin numbers for non-crossing lattice path enumeration

Introduction

Motzkin numbers count several different combinatorial objects that turn out to be equivalent. The most visual interpretation is a path-counting problem: starting at (0,0), you move to the right using three allowed step types—an up step, a horizontal step, or a down step—and you must finish at height zero without ever dipping below the horizontal axis. The number of valid paths of length n is the Motzkin number M(n). The same sequence also counts ways to draw non-crossing chords among points on a circle and several families of recursively defined trees and partitions.

This calculator gives you the value of M(n) for any integer input from 0 to 100. That makes it useful both as a quick lookup tool and as a teaching aid when you want to see how quickly the sequence grows. Because the values become large very fast, the page uses JavaScript BigInt arithmetic so it can compute exact integers rather than rounded approximations.

The first few Motzkin numbers are 1, 1, 2, 4, 9, 21, 51, 127, 323, 835, and so on. Even if you have never seen the sequence before, the pattern becomes easier to understand once you think in terms of path construction. A valid 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 valid subproblems. That decomposition is exactly what drives the recurrence used by the calculator.

How to Use

Using the calculator is simple. Enter a whole number n in the input field, then press Calculate M(n). The result panel shows three pieces of information: the input value n, the Motzkin number M(n), and a growth ratio comparing M(n) with the previous term M(n−1) when that comparison exists.

The input has no physical unit because Motzkin numbers are pure counts. Here, n means the position in the sequence and also the total number of steps in the corresponding lattice path model. For example, if you enter 3, the calculator counts all valid length-3 Motzkin paths that start and end on the axis and never go below it.

If the exact integer is very long, the visible result is shortened for readability and the page notes how many digits the full value contains. The copy button still copies the full exact expression in the form M(n) = value. That is handy if you want to paste the result into notes, a worksheet, or a programming project.

For best results, use nonnegative integers only. The form already enforces a range from 0 to 100, which is a practical limit for a browser-based calculator. Values in that range are large enough to be interesting while still being computed quickly on ordinary devices.

Formula

Motzkin numbers are commonly defined by a recurrence relation. The page preserves the standard MathML form below because it expresses the structure of the counting argument clearly:

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

The initial conditions are M(0) = 1 and M(1) = 1. In plain language, the recurrence says that every valid path of length n falls into one of two categories. First, it may start with a horizontal step, leaving a valid path of length n−1. Second, it may start with an up step that is matched later by a down step; the region inside that matched pair contributes one smaller Motzkin path, and the remainder after the pair contributes another. Summing over all possible split points gives the summation term.

This is why dynamic programming works so well. Instead of recomputing the same smaller values again and again, the script builds the sequence from the bottom up. That approach is much faster and more reliable than naive recursion, especially once n gets moderately large.

Worked Example

Suppose you want to find M(3). Start from the recurrence:

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

Now compute the smaller term first:

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

Substitute that back in:

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

You can also verify the answer directly by listing the four valid paths of length 3: HHH, UDH, UHD, and HUD. This small example is useful because it shows both sides of the theory: the recurrence gives a fast computational method, while the path interpretation explains what the number actually counts.

What the Result Means

When the calculator returns M(n), it is giving the exact number of valid Motzkin structures of size n. If you are thinking in terms of lattice paths, the result is the count of all legal paths with n steps. If you are thinking in terms of non-crossing chords, it is the count of all admissible chord configurations on the corresponding number of points. The same integer can therefore answer 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 helps you see how the sequence expands as n increases. For small values, the ratio moves around noticeably, but as n grows it trends toward the sequence's asymptotic growth behavior. This is a quick way to build intuition about how rapidly the counts become large.

Because the displayed value may be shortened when it has many digits, remember that the underlying computation is still exact. The truncation is only a presentation choice to keep the page readable. If you need the full integer, use the copy button or adapt the same recurrence in your own code.

Applications and Assumptions

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

This calculator assumes the standard unweighted Motzkin model. Every allowed step has equal status in the count, paths are constrained never 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, forbidden plateaus, or modular arithmetic, then you are working with a variant rather than the basic sequence shown here.

It is also worth noting what the calculator does not do. It does not list every 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 many classroom, puzzle, and algorithm-analysis tasks, that is exactly the quantity 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 hard-looking problem into a form that is easier to reason about or compute.

Motzkin Sequence Reference

This quick reference table gives a few benchmark 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 the sequence accelerates.

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 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 - Compute Motzkin Sequence Values and Lattice Path Counts to your website.