{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

MIT6_042JF10_rec04_sol

# MIT6_042JF10_rec04_sol - 6.042/18.062J Mathematics for...

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

6.042/18.062J Mathematics for Computer Science September 22, 2010 Tom Leighton and Marten van Dijk Notes for Recitation 4 1 The Pulverizer We saw in lecture that the greatest common divisor (GCD) of two numbers can be written as a linear combination of them. 1 That is, no matter which pair of integers a and b we are given, there is always a pair of integer coeﬃcients s and t such that gcd( a, b ) = sa + tb. However, the proof was nonconstructive : it didn’t suggest a way for finding such s and t . That job is tackled by a mathematical tool that dates to sixth-century India, where it was called kuttak , which means “The Pulverizer”. Today, the Pulverizer is more commonly known as “the extended Euclidean GCD algorithm”, but that’s lame. We’re sticking with “Pulverizer”. Euclid’s algorithm for finding the GCD of two numbers relies on repeated application of the equation: gcd( a, b ) = gcd( b, rem ( a, b )) which was proved in lecture (see the notes “Number Theory I”). For example, we can compute the GCD of 259 and 70 as follows: gcd(259 , 70) = gcd(70 , 49) since rem (259 , 70) = 49 = gcd(49 , 21) since rem (70 , 49) = 21 = gcd(21 , 7) since rem (49 , 21) = 7 = gcd(7 , 0) since rem (21 , 7) = 0 = 7 . The Pulverizer goes through the same steps, but requires some extra bookkeeping along the way: as we compute gcd( a, b ), we keep track of how to write each of the remainders (49, 21, and 7, in the example) as a linear combination of a and b (this is worthwhile, because our objective is to write the last nonzero remainder, which is the GCD, as such a linear 1 In fact, we proved that among all positive linear combinations of the numbers their GCD is the smallest.

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

View Full Document
2 Recitation 4 combination). For our example, here is this extra bookkeeping: x y ( rem ( x, y )) = y x q · 259 70 49 = 259 3 · 70 70 49 21 = 70 1 · 49 = 70 1 · (259 3 · 70) = 1 · 259 + 4 · 70 49 21 7 = 49 2 · 21 = (259 3 · 70) 2 · ( 1 · 259 + 4 · 70) = 3 · 259 11 · 70 21 7 0 We began by initializing two variables, x = a and y = b . In the first two columns above, we carried out Euclid’s algorithm. At each step, we computed rem ( x, y ), which can be written in the form x q y . (Remember
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}