Lecture 2: The Euclidean Algorithm
This lecture discusses one of the earliest and most important mathematical
algorithms. The Euclidean algorithm computes the greatest common divisor
of two integers (it can be extended to other domains such as polynomials).
This algorithm, not commonly taught when gcds are introduced in High School
mathematics, is a much more efficient way to compute the gcd than using
integer factorization.
The algorithm can be stated in a few lines, using recursion, yet it has
many fascinating properties, and its complete analysis was a major
undertaking.
Background Material
- Euclidean division (division with remainder).
a = q*b + r, where 0 <= r < b. The quotient q and remainder r are unique.
- Definition. g = gcd(a,b) iff g|a and g|b (m|n iff n = q*m for some q)
and if e|a and e|b then e|g.
- Factorization into primes (every integer can be written uniquely
(upto order) as a product of prime numbers. This is called the fundamental
theorem of arithmetic. See lecture 1 on Unique
Factorization.
Reading
- Chapter sections 1.3-1.4 of the text.
Also study Maple's igcd, igcdex, gcd, and gcdex commands.
Topics
- Definition of greatest common divisors
- Euclidean algorithm
gcd(a,b)
- if b = 0 then return a;
- else return gcd(b,a mod b)
- Proof of correctness
- The extended Euclidean algorithm (recursive version)
- Iterative version of the algorithm and remainder sequences
- Fibonacci numbers and an upper bound on the number of divisions
- The Fibonacci numbers are defined by F_0 = 0, F_1 = 1,
F_n = F_{n-1} + F_{n-2} for n > 1.
- F_n = 1/sqrt(5)*(phi^n - phihat^n), where phi = (1 + sqrt(5))/2 and
phihat = (1 - sqrt(5))/2 are the roots of x^2-x-1=0. F_n is the nearest
integer to 1/sqrt(5)*phi^n.
- Let 0 <= b < a <= N and n = the maximum number of division steps
required to compute gcd(a,b) using the Euclidean algorithm. Then
n <= 2lg(N). This constant in this bound is not tight.
- Let 0 <= b < a <= N. The maximum number of division steps occurs
when when a = F_{n+2} and b = F_{n+1}. From this it follows that the
n <= log[phi](N) + log[phi](sqrt(5)/phi). log[phi](N) is approximately
1.44*lg(N).
- The probability that two random integers are relatively prime.
Maple worksheets and other resources
- euclid.mw - Maple worksheet on the Euclidean
algorithm.
- euclid.pdf - Lecture notes on the Euclidean
algorithm (to be posted).
Created: April 14, 2006 by jjohnson@cs.drexel.edu