There are no approved revisions of this page, so it may
not have been
reviewed.
This article page is a stub, please help by expanding it.
The Euclidean algorithm (also called Euclid's algorithm) is an efficient method for computing the greatest common divisor (GCD), also known as the greatest common factor (GCF) or highest common factor (HCF). It is named after the Greek mathematician Euclid, who described it in Books VII and X of his Elements.[1]
Algorithmic efficiency
Number of steps
Number of steps in the Euclidean algorithm for
. Red points indicate relatively few steps (quick), whereas yellow, green and blue points indicate successively more steps (slow). The largest blue area follows the line
, where
represents the
Golden ratio.
The number of steps to calculate the
GCD of two
natural numbers,
and
, may be denoted by
.
[2] If
is the
GCD of
and
, then
and
for two
coprime numbers
and
. Then
-
as may be seen by dividing all the steps in the Euclidean algorithm by
.
[3] By the same argument, the number of steps remains the same if
and
are multiplied by a common factor
-
Therefore, the number of steps
may vary dramatically between neighboring pairs of numbers, such as
and
, depending on the size of the two
GCDs.
The recursive nature of the Euclidean algorithm gives another equation
-
where
by assumption.
[2]
Worst case number of steps
If the Euclidean algorithm requires
steps for a pair of
natural numbers , the smallest values of
and
for which this is true are the
Fibonacci numbers and
, respectively.
[4] This can be shown by
induction.
[5] If
,
divides
with no remainder; the smallest natural numbers for which this is true is
and
, which are
and
, respectively. Now assume that the result holds for all values of
up to
. The first step of the
-step algorithm is
-
and the second step is
-
Since the algorithm is recursive, it required
steps to find
and their smallest values are
and
. The smallest value of
is therefore when
, which gives
a = b + r0 = FM + 1 + FM = FM + 2 |
. This proof, published by
Gabriel Lamé in 1844, represents the beginning of
computational complexity theory,
[6] and also the first practical application of the
Fibonacci numbers.
[4]
This result suffices to show that the number of steps in Euclid's algorithm can never be more than five times the number of its digits (base 10).
[7] For if the algorithm requires
steps, then
is greater than or equal to
which in turn is greater than or equal to
, where
is the
golden ratio. Since
, then
. Since
log10 ϕ > , < log10 ϕ logϕ b = log10 b. |
Thus,
. Thus, the Euclidean algorithm always needs less than
divisions, where
is the number of digits in the smaller number
.
Applications
Factorization algorithms
Calculating a greatest common divisor is an essential step in several integer factorization algorithms,[8] such as Pollard's rho algorithm,[9] Shor's algorithm,[10] Dixon's factorization method[11] and the Lenstra elliptic curve factorization.[12] The Euclidean algorithm may be used to find this GCD efficiently. Continued fraction factorization uses continued fractions, which are determined using Euclid's algorithm.[13]
Domains
The Euclidean algorithm can be adapted to some other domains. Those domains in which the Euclidean algorithm can be adapted and implemented are then called Euclidean domains.
Notes
- ↑ Thomas L. Heath, The Thirteen Books of Euclid's Elements, 2nd ed. [Facsimile. Original publication: Cambridge University Press, 1925], 1956, Dover Publications.
- ↑ 2.0 2.1 Knuth, p. 344.
- ↑ Ore, p. 45.
- ↑ 4.0 4.1 Knuth, p. 343.
- ↑ Mollin, p. 21.
- ↑ LeVeque, p. 35.
- ↑ Mollin, pp. 21–22.
- ↑ Crandall R., Pomerance C. (2001). Prime Numbers: A Computational Perspective (1st ed.). New York: Springer-Verlag. pp. 225–349. ISBN 0-387-94777-9.
- ↑ Knuth, pp. 369–371.
- ↑ Shor P.W. (1997). “Polynomial-Time Algorithms for Prime Factorization and Discrete Logarithms on a Quantum Computer”. SIAM J. Sci. Statist. Comput. 26: pp. 1484.
- ↑ Dixon J.D. (1981). “Asymptotically fast factorization of integers”. Math. Comput. 36 (153): pp. 255–260. doi:10.2307/2007743. http://jstor.org/stable/2007743.
- ↑ Lenstra Jr. H.W. (1987). “Factoring integers with elliptic curves”. Annals of Mathematics 126 (3): pp. 649–673. doi:10.2307/1971363. http://jstor.org/stable/1971363.
- ↑ Knuth, pp. 380–384.