Skip to content

Resource · Guide or article

Liu Hui's π Algorithm

Historical math background on how Liu Hui bounded pi by repeatedly doubling the sides of a polygon inscribed in a circle. It suits candidates who enjoy numeric approximation puzzles more than anyone studying core interview topics.

Reviewed

Open the original: Liu Hui's π Algorithm (opens the original site in a new tab)

Add to a roadmap

Keep this resource with a roadmap you follow. It appears as your own extra resource; the roadmap's steps don't change and it doesn't count toward your tracked steps.

Source content: English

Liu Hui remarked in his commentary to The Nine Chapters on the Mathematical Art, that the ratio of the circumference of an inscribed hexagon to the diameter of the circle was three, hence π must be greater than three. He went on to provide a detailed step-by-step description of an iterative algorithm to calculate π to any required accuracy based on bisecting polygons; he calculated π to between 3.141024 and 3.142708 with a 96-gon; he suggested that 3.14 was a good enough approximation, and expressed π as 157/50; he admitted that this number was a bit small. Later he invented an ingenious quick method to improve on it, and obtained π ≈ 3.1416 with only a 96-gon, with an accuracy comparable to that from a 1536-gon. His most important contribution in this area was his simple iterative π algorithm. Liu Hui's method of calculating the area of a circle. Further, Liu Hui proved that the area of a circle is half of its circumference multiplied by its radius. He said:

PrepKit overview

PrepKit editors wrote and reviewed this overview from the source repository. It is not text from the resource itself.

Suited to
The source does not state a level
Format
Lesson

What it covers

  • Opening account of Liu Hui's results: bounds from a 96-gon, the 157/50 approximation, and his faster refinement.
  • Area of a circle section: why the polygon's area approaches the circle's, ending at A = r x C/2.
  • Iterative algorithm section: bisecting a hexagon side and applying the Pythagorean theorem (Gou Gu) to get the 12-gon side from the 6-gon side.

How to use it

PrepKit study advice, not a claim made by the source.

Work through the side-doubling step on paper from a hexagon to a 24-gon, then write a short loop that repeats it and prints the pi estimate after each round. You are done when you can explain why each doubling tightens the estimate.

Scope and limitations

Mostly history and geometry with little direct interview relevance. The key formulas appear only as images from Wikimedia, and the single reference is Wikipedia. No exercises or complexity discussion.

Access and format

English Markdown README on GitHub, free to read, in the MIT-licensed trekhleb/javascript-algorithms repository.

Reviewed by PrepKit on Oct 2, 2026. Listing source commit: 85293e3e2b88

Evidence behind this overview
  • src/algorithms/math/liu-hui/README.md

Pages that include this

Get the PrepKit newsletter

Optional. You don't need it to use PrepKit.

How we handle your email