DOC PREVIEW
MIT 6 042J - Notes for Recitation 6

This preview shows page 1-2 out of 6 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 6 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 6 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 6 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

The PulverizerProblem: The Pulverizer!Problem: The Fibonacci numbers. Again.Problem: The power of 3.6.042/18.062J Mathematics for Computer Science February 18, 2005 Srini Devadas and Eric Lehman Notes for Recitation 6 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 coefficients 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, a rem 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 259 rem 70 = 49 = gcd(49, 21) since 70 rem 49 = 21 = gcd(21, 7) since 49 rem 21 = 7 = gcd(7, 0) since 21 rem 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 1In fact, we proved that among all positive linear combinations of the numbers their GCD is the smallest.2 Recitation 6 linear combination). For our example, here is this extra bookkeeping: x y (x rem y) = x − q · y 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) = 259 − 11 · 703 · 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 x rem y, which can be written in the form x − q · y. (Remember that the Division Algorithm says x = q · y + r, where r is the remainder. We get r = x − q · y by rearranging terms.) Then we replaced x and y in this equation with equivalent linear combinations of a and b, which we already had computed. After simplifying, we were left with a linear combination of a and b that was equal to the remainder as desired. The final solution is boxed.Recitation 6 3 2 Problem: The Pulverizer! There is a pond. Inside the pond there are n pebbles, arranged in a cycle. A frog is sitting on one of the pebbles. Whenever he jumps, he lands exactly k pebbles away in the clockwise direction, where 0 < k < n. The frog’s meal, a delicious worm, lies on the pebble right next to his, in the clockwise direction. (a) Describe a situation where the frog can’t reach the worm. Solution. If k | n (say k = 3 and n = 6), then no number of jumps will lead the frog to the worm, as the frog will be returning to his original pebble ad infinitum. (b) In a situation where the frog can actually reach the worm, explain how to use the Pulverizer to find how many jumps the frog will need. Solution. Suppose the frog can reach the worm. When he actually reaches it, he has jumped a number of times, say j, and he has travelled around the cycle a number of times, call it c. Then, the distance that the frog has covered is both j · k and c · n + 1, so that jk = cn + 1. But this means that 1 can be written as a linear combination of n and k: (−c)n + jk = 1. Since 1 is positive, we conclude that it is a positive linear combination of n and k. And since it is the smallest positive integer, we also conclude that it is the smallest positive linear combination of n and k. But we have proved in lecture that the smallest positive linear combination of two integers is their GCD. So, the GCD of n and k is 1: gcd(n, k) = 1 and we can use the Pulverizer to find −c and j. (c) Compute the number of jumps if n = 50 and k = 21. Anything strange? Solution. We go through the steps as described in Section 1 (see the table below) to get that 1 = 8 · 50 − 19 · 21, or 1 = −(−8) · 50 + (−19) · 21. Hence, c = −8 and j = −19, which makes little sense. What does it mean for the frog to make −19 jumps? The point is that the Pulverizer is guaranteed to give us the integers coefficients of a linear combination that equals the GCD, but it promises nothing about the signs of those coefficients —which, in this case we wanted them to be − and +. To get coefficients of the desired sign, we have to think more (and much less after the next lecture). So, we know 1 = 8 · 50 − 19 · 21. Or, to obtain meaningful signs for the numbers, 19 · 21 = 8 · 50 − 1. That is, after 19 jumps the frog will have covered 8 full cycles but 1 pebble. So, he will be right next to his original pebble, but in the counter-clockwise direction. Given this, how can he reach the pebble he is after?4 Recitation 6 Well, if he makes 19 more jumps, he will land 2 pebbles away from his original position in the counter-clockwise direction. Another 19 jumps will lead him 3 pebbles away, and so on. After a total of 49 sets of 19 jumps, he will be 49 pebbles away from its original position in the counter-clockwise direction, which is of course the worm’s pebble. Then, the frog will have made 49 ∗ 19 = 931 jumps. Here is the table produced by the Pulverizer: x y (x rem y) = x − q · y 50 21 8 = 50 − 2 · 21 21 8 5 = 21 − 2 · 8 = 21 − 2 · (50 − 2 · 21) = −2 · 50 + 5 · 21 8 5 3 = 8 − 1 · 5 = (50 − 2 · 21) − 1 · (−2 · …


View Full Document

MIT 6 042J - Notes for Recitation 6

Documents in this Course
Counting

Counting

55 pages

Graphs

Graphs

19 pages

Proofs

Proofs

14 pages

Proofs

Proofs

18 pages

Proofs

Proofs

18 pages

Quiz 1

Quiz 1

9 pages

Quiz 2

Quiz 2

11 pages

Load more
Download Notes for Recitation 6
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Notes for Recitation 6 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Notes for Recitation 6 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?