Euclidean Algorithm

Algorithm

Repeatedly replace (a,b) with (b, a mod b) until b=0. The last nonzero remainder is gcd(a,b).

Examples

Example 1. gcd(252,105).

Solution. 252=2·105+42; 105=2·42+21; 42=2·21+0. gcd=21.

In Depth

The Euclidean algorithm computes \(\gcd(a,b)\) by repeated division: \(\gcd(a,b)=\gcd(b,a\bmod b)\), terminating when the remainder is 0. It is one of the oldest algorithms, appearing in Euclid's Elements (c. 300 BCE), and runs in \(O(\log\min(a,b))\) steps.

The extended Euclidean algorithm also finds integers \(x,y\) such that \(ax+by=\gcd(a,b)\) (Bézout's identity). These coefficients are used to compute modular inverses: if \(\gcd(a,n)=1\), then \(a^{-1}\bmod n\) is the \(x\) from \(ax+ny=1\).

Worst-case inputs are consecutive Fibonacci numbers: \(\gcd(F_{n+1},F_n)\) requires exactly \(n\) steps. This proves the algorithm's \(O(\log n)\) bound is tight. The Fibonacci numbers are the 'most difficult' inputs for the Euclidean algorithm.

The binary GCD algorithm replaces division with subtraction and halving, using only bit shifts and subtraction — faster on hardware where division is expensive. It achieves the same \(O(\log n)\) complexity.

The Euclidean algorithm generalizes to any Euclidean domain: a ring with a 'size' function where division with remainder is possible. Examples include the Gaussian integers \(\mathbb{Z}[i]\) and polynomial rings \(F[x]\) over a field. In these settings, the algorithm computes GCDs of complex numbers or polynomials.

Key Properties & Applications

The Euclidean algorithm is the oldest non-trivial algorithm still in widespread use. Its time complexity is \(O(\log\min(a,b))\) divisions, or \(O(\log^2 n)\) bit operations. For large integers, fast multiplication (Karatsuba, FFT-based) reduces this to \(O(M(n)\log n)\) where \(M(n)\) is the multiplication cost.

The subresultant algorithm extends the Euclidean algorithm to polynomials, computing GCDs without coefficient explosion. It is used in computer algebra systems (Mathematica, Maple, SageMath) for symbolic computation.

The Euclidean algorithm has a beautiful connection to the Stern–Brocot tree: the sequence of quotients in the algorithm traces a path in the tree from the root to the fraction \(a/b\). This gives a bijection between positive rationals and finite binary strings.

Further Reading & Context

The study of euclidean algorithm connects to many areas of mathematics and its applications. Understanding the foundational definitions and theorems provides the basis for advanced work in analysis, algebra, and applied mathematics.

Historical development: most mathematical concepts evolved over centuries, with contributions from mathematicians across many cultures. The modern axiomatic treatment provides rigor, while computational tools enable practical application.

In modern mathematics, this topic appears in graduate courses and research across pure and applied mathematics. Connections to computer science, physics, and engineering make it a versatile and important area of study. Mastery of the core results and techniques opens doors to research in number theory, analysis, geometry, and beyond.

Recommended next steps: work through the standard theorems with full proofs, explore the connections to related topics listed above, and practice with a variety of problems ranging from computational exercises to theoretical proofs. The interplay between different areas of mathematics is one of the subject's greatest rewards.

Deep Dive: Euclidean Algorithm

This lesson extends core ideas for euclidean algorithm with rigorous reasoning, edge-case checks, and application framing in number theory.

Practice Set

Practice. Derive one main result on this page and validate with a numeric or geometric check.

Goal. Confirm assumptions, transformation steps, and final interpretation.

References & Editorial Notes

  • Stewart, Calculus.
  • Strang, Introduction to Linear Algebra.
  • Apostol, Mathematical Analysis.

Last editorial review: 2026-04-14.