The harmonic number H(n) is the sum 1 + 1/2 + 1/3 + … + 1/n, a number that grows like the logarithm. The harmonic number calculator gives H(n) and three classic uses: the draws to collect n coupons, the overhang of a stack of books and the average comparisons of quicksort.
How the calculation works
- Enter the number n of terms: for a coupon collection, the number of different coupons, for a stack, the number of books, for a sort, the number of items.
- The calculator computes the harmonic number H(n) = 1 + 1/2 + 1/3 + … + 1/n with the asymptotic formula ln n + γ + 1/(2n) − 1/(12n²) + 1/(120n⁴), where γ = 0.5772 is the Euler-Mascheroni constant.
- The formula is accurate to about 8 digits from n = 5, and the error falls fast as n grows.
- Read the harmonic number and its uses: the coupon collector, the overhang of a stack of books and the average cost of quicksort.
Example
Take n = 50. The harmonic number is H(50) = ln 50 + 0.5772 + 1/100 − 1/30,000 = 4.4992. A collector who wants all 50 different cards from random packs needs on average 50 × 4.4992 = 225.0 draws. A stack of 50 identical books, each balanced on the next, can overhang the table by H(50) / 2 = 2.250 book lengths. A quicksort on 50 items makes on average 2 × 51 × 4.4992 − 200 = 259 comparisons. H(50) − ln 50 is 0.5872, close to the constant of Euler 0.5772.
Why it matters
The calculator helps students of probability, computer science and analysis, and curious people, to compute a harmonic number for a large n without adding all the terms, and to see where it shows up. It is useful for the analysis of algorithms, for estimating the size of a collection, and for the puzzle of the leaning stack.
Good to know
Use the result for n of 5 or more, where the formula is very accurate. For a small n, add the inverses by hand. Remember that the coupon collector result is an average: the real number of draws varies a lot, and the last coupons take the most time, since the final one alone needs about n draws on average.
Related tools
The coupon collector calculator gives the details of the collection problem with the probabilities, the harmonic mean calculator uses the inverses in an average, the logarithm calculator gives ln n, and the expected value calculator covers the averages of random variables.