Harmonic Number Calculator
Compute the harmonic number H_n exactly from its series definition, with optional breakdown and a fast logarithmic approximation for larger n values.
Harmonic Number Calculator
Compute the harmonic number H_n exactly from its series definition, with optional breakdown and a fast logarithmic approximation for larger n values.
About the harmonic number calculator
The nth harmonic number is the finite sum H_n = 1 + 1/2 + 1/3 + ... + 1/n. It looks simple, but it appears in a surprisingly wide range of topics: number theory, analysis, algorithm design, combinatorics, and probability. This calculator evaluates the series directly, giving you the exact partial sum for a chosen positive integer n. It can also show an asymptotic approximation and, for smaller values, a readable breakdown of the terms that make up the sum.
Harmonic numbers grow very slowly. They increase without bound as n gets larger, but the growth is logarithmic rather than linear. That means H_10 is only a little above 2.9, H_100 is about 5.19, and even H_1,000,000 is only around 14.39. This slow growth is one reason harmonic numbers appear in complexity analysis. Many algorithms, especially those involving repeated divisions, heap behavior, or coupon-collector-style expectations, produce formulas that contain H_n or expressions closely related to it.
A classic approximation is H_n ≈ ln(n) + γ + 1/(2n), where γ is the Euler-Mascheroni constant. This estimate becomes better as n increases and is often used when you want intuition without summing every term by hand. The calculator shows that approximation on demand so you can compare the exact partial sum against the logarithmic model. For moderate or large n, the approximation is usually very close.
The sum breakdown option is useful for teaching, checking homework, and seeing how the series is built. For readability, the calculator displays only the first twenty terms explicitly and then adds an ellipsis if n is larger. That keeps the output practical while still making the structure of the series clear.
Because harmonic numbers are defined only for positive integers in this context, the calculator rejects zero, negative values, and non-integers. It also caps n to keep the browser-side computation responsive. If you need to estimate behavior for very large n, the approximation is often the more informative quantity anyway. Whether you are studying asymptotic analysis, expected values, or classical series, the harmonic number is a small object with large mathematical reach.
Harmonic number examples
These examples show the exact sum and how quickly the approximation becomes useful.
| Input | Output | Notes |
|---|---|---|
| n = 1 | 1.0000000000 | The first harmonic number is just the first term of the series. |
| n = 5 | 2.2833333333 | H_5 = 1 + 1/2 + 1/3 + 1/4 + 1/5. This is a common classroom example because it is still easy to inspect term by term. |
| n = 10 | 2.9289682540 | The series continues to grow, but slowly. Even after ten terms the sum is still below 3. |
How to use the harmonic number calculator
- Enter a positive integer n in the Term Number field.
- Choose whether to display the term-by-term breakdown, the approximation, or both.
- Click "Calculate" to compute H_n and show the requested extra information.
- Use "Reset" to clear the form and return to the default options.
Harmonic number FAQ
Do harmonic numbers converge to a fixed value?
No. The harmonic series diverges, so H_n grows without bound as n increases. However, it grows extremely slowly, roughly like the natural logarithm of n.
Why is there a logarithm in the approximation?
The graph of 1/x is closely related to the area under a curve, and comparing the sum 1 + 1/2 + ... + 1/n to the integral of 1/x naturally introduces ln(n). The Euler-Mascheroni constant and correction terms refine that rough comparison into a strong approximation.
Where do harmonic numbers appear in computer science?
They show up in average-case analyses of algorithms such as hashing, coupon collection, divide-and-conquer recurrences, and data-structure operations. When repeated costs shrink like 1/k, a harmonic number often appears in the total running time or expected value.
Why limit n to one million?
This page computes the exact sum directly in the browser, so an upper bound keeps the interaction fast and predictable. For larger values, the approximation usually provides the practical insight you need with almost no cost.