# Lecture 5: The Euclidean Algorithm

This lecture introduces 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.

• Lecture 4 on Fibonacci numbers (they arise in the analysis of the Euclidean algorithm.
Also study Maple's igcd, igcdex, gcd, and gcdex commands.

### Topics

• Definition of greatest common divisors
• Existence proof. Let S = {a*x+b*y | x,y are integers}. Let g be the smallest positive element of S. Then g = gcd(a,b).
• Euclidean algorithm
gcd(a,b)
1. if b = 0 then return a;
2. else return gcd(b,a mod b)
• Proof of correctness
• Iterative version of the algorithm
• Upper bound on the number of divisions
• The extended Euclidean algorithm (recursive and iterative versions)

### Maple worksheets and programs and other resources

• euclid.mws - Maple worksheet on the Euclidean algorithm.
• euclid.pdf - notes from class (to be posted).
Created: Oct. 20, 2005 by jjohnson@cs.drexel.edu