EuclideanAlgorithm - Euclids Algorithm The Greatest Common...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Euclid’s Algorithm The Greatest Common Divisor(GCD) of two integers is defined as follows: An integer c is called the GCD(a,b) (read as the greatest common divisor of integers a and b) if the following 2 conditions hold: 1) c | a c | b 2) For any common divisor d of a and b, d | c. Rule 2 ensures that the divisor c is the greatest of all the common divisors of a and b. One way we could find the GCD of two integers is by trial and error. Another way is that we could prime factorize each integer, and from the prime factorization, see which factors are common between the two integers. However, both of these become very time consuming as soon as the integers are relatively large. However, Euclid devised a fairly simple and efficient algorithm to determine the GCD of two integers. The algorithm basically makes use of the division algorithm repeatedly. Let’s say you are trying to find the GCD(a,b), where a and b are integers with a b > 0 Euclid’s algorithm says to write out the following: a = q 1 b + r 1 , where 0 < r < b b = q 2 r 1 + r 2 , where 0 < r 2 < r 1 r 1 = q 3 r 2 + r 3 , where 0 < r 3 < r 2 . . r i = q i+2 r i+1 + r i+2 , where 0 < r i+2 < r i+1 . . r k-1 = q k+1 r k Euclid’s algorithm says that the GCD(a,b) = r k This might make more sense if we look at an example: Consider computing GCD(125, 87) 125 = 1*87 + 38 87 = 2*38 + 11 38 = 3*11 + 5 11 = 2*5 + 1 5 = 5*1 Thus, we find that GCD(125,87) = 1.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Let’s look at one more quickly, GCD(125, 20) 125 = 6*20 + 5 20 = 4*5, thus, the GCD(125,20) = 5 Proof That Euclid’s Algorithm Works Now, we should prove that this algorithm really does always give us the GCD of the two numbers “passed to it”. First I will show that the number the algorithm produces is indeed a divisor of a and b. a = q 1 b + r 1 , where 0 < r < b b = q 2 r 1 + r 2 , where 0 < r 2 < r 1 r 1 = q 3 r 2 + r 3 , where 0 < r 3 < r 2 . . r i = q i+2 r i+1 + r i+2 , where 0 < r i+2 < r i+1 . . r k-1 = q k+1 r k From the last equation, we know that r k | r k-1 . So, we know that we can express r k-1 = cr k , where c is an integer. Now consider the previous equation: r k-2 = q k r k-1 + r k = q k cr k , + r k = r k (q k c + 1) Thus, we have that r k | r k-2 . In our equation previous to that one, we have:
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 07/13/2011 for the course CIS 3362 taught by Professor Staff during the Fall '08 term at University of Central Florida.

Page1 / 8

EuclideanAlgorithm - Euclids Algorithm The Greatest Common...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online