Dyck Path Counter
Enter a semilength n to count the Dyck paths of that size.
Result
How it is calculated
The number of Dyck paths of semilength n is the Catalan number C(n) = (2n)! / (n! × (n+1)!), which is the same as C(2n, n) / (n+1). Instead of using large factorials, the tool builds it step by step with C(0) = 1 and C(k) = C(k−1) × 2(2k−1) / (k+1), using exact whole-number arithmetic. A path of semilength n has n up steps and n down steps, so 2n steps in total, which the tool also reports. Only whole numbers from 0 to 30 are accepted: C(30) = 3,814,986,502,092,304 is still exact, but larger values are not computed, and decimals, negatives or an empty field show no result. It also echoes your n.
Worked example
Take n = 4: four up steps and four down steps, 8 steps in all. Start from C(0) = 1. Then C(1) = 1 × 2 × 1 / 2 = 1, C(2) = 1 × 2 × 3 / 3 = 2, C(3) = 2 × 2 × 5 / 4 = 5, and C(4) = 5 × 2 × 7 / 5 = 14. So the tool shows 14 paths and 8 steps, which matches C(8, 4) / 5 = 70 / 5 = 14. Those 14 are exactly the 14 ways to write four pairs of parentheses correctly.
Common mistakes
- Entering the total number of steps (8) instead of the semilength (4). The tool expects n, the number of up steps, and doubles it for the length.
- Confusing Dyck paths with all up/down paths. Without the rule that the path never goes below the start, there would be C(2n, n) paths, which for n = 4 is 70, not 14.
- Entering a decimal such as 2.5, or a negative n. Only whole numbers from 0 up are valid, and anything else gives no result.
- Entering n above 30 and expecting a very large number. The tool stops at 30 to keep the count exact, so for bigger n you need a big-integer tool.
- Assuming n = 0 gives zero. There is exactly one empty path, so the count for n = 0 is 1 (with 0 steps).
About this calculator
A Dyck path is a staircase-like lattice path made of "up" and "down" steps that starts and ends at the same height and never dips below its starting level — equivalent to a correctly balanced sequence of parentheses, where an "up" step is an opening bracket and a "down" step is a closing one. This calculator counts how many distinct Dyck paths exist for a given semilength n (n up-steps and n down-steps, 2n steps total), a count that equals the nth Catalan number, C(2n,n)/(n+1).
Catalan numbers via Dyck paths show up constantly in combinatorics and computer science: they count the ways to correctly match parentheses in an expression, the number of distinct binary search trees with n nodes, the ways to triangulate a convex polygon, and valid push/pop sequences on a stack — which is why the same C(2n,n)/(n+1) formula keeps reappearing across seemingly unrelated counting problems in discrete math courses.
Was this helpful?
You can pick up to 3 reactions.
Popular calculators
Loan Calculator
Monthly payment, total interest and full amortization schedule.
Percentage Calculator
Percent change, percent of, and ratio calculations.
Discount Calculator
Calculate final price, savings, and discount amount.
BMI Calculator
Body mass index from height and weight (metric or imperial).
Age Calculator
Compute your exact age in years, months and days from a birth date.
Compound Interest Calculator
Calculate the final amount and interest earned with compounding.
All Calculators
- Loan Calculator
- Profit Calculator
- Discount Calculator
- BMI Calculator
- Percentage Calculator
- Ideal Weight Calculator
- Age Calculator
- Pregnancy Due Date Calculator
- Compound Interest Calculator
- BMR Calculator (Basal Metabolic Rate)
- Tip Calculator
- Fuel Cost Calculator
- Date Difference Calculator
- Sleep Cycle Calculator
- Daily Water Intake Calculator
- Simple Interest Calculator
- Heart Rate Zones Calculator
- Running Pace Calculator
- Pet Age Calculator
- Calories Burned Calculator
- Macro Calculator
- TDEE Calculator (Total Daily Energy Expenditure)
- Waist-to-Hip Ratio Calculator
- Honor Roll Calculator
- One Rep Max (1RM) Calculator
- Ovulation Calculator
- Electricity Cost Calculator
- Unit Price Calculator
- Savings Goal Calculator
- Break-Even Point Calculator
- Paint Calculator
- Course Grade Average Calculator
- Business Days Calculator
- Time Duration Calculator
- Fuel Economy Calculator
- Temperature Converter
- Tile Calculator
- Aspect Ratio Calculator
- Roman Numeral Converter
- Goal Weight Timeline Calculator
- Salary Converter (Hourly to Annual)
- Credit Card Validator (Luhn)
- Body Surface Area (BSA) Calculator
- Feels-Like Temperature Calculator
- Ohm’s Law Calculator
- PPI (Pixel Density) Calculator
- Molar Mass Calculator
- Zodiac Sign Calculator (Western + Chinese)
- IBAN Validator
- Shoe Size Converter
- Country Info & Dialing Code Lookup
- Time Zone Difference (World Clock)
- CAGR (Compound Annual Growth Rate) Calculator
- Rule of 72 Calculator
- Blood Alcohol Content (BAC) Calculator
- Lean Body Mass (LBM) Calculator
- Pythagorean Theorem Calculator
- Speed Converter
- Download Time Calculator
- Date Calculator (Add/Subtract)
No calculators found
Comments