This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: 1. Greatest common divisor a. Function Euclid(a,b) If b = 0, return a Return Euclid(b, a mod b) b. How fast is it? Lemma: if a >= b then a and b < a/2. The larger of a,b shrinks by at least one bit on each recursive call. Suppose a,b are n bits long. Therefore, at most 2n recursive calls. Therefore, total running time = O(n 3 ) c. How could you convince that someone that gcd(a,b) = 23? Suppose you could find integer x,y such that ax + by = 23. Any divisor of a,b also divides ax + by and therefore, divides 23, and therefore, cannot be more than 23. Lemma: If d  a and d  b, and d = ax + by for integers x,y then d = gcd(a,b). Such integers x,y always exist and can be found by a small modification to Euclids alg. d. Ex: Gcd(231, 60) = gcd(60, 51) = gcd(51,9) = gcd(9,6) = gcd(6,3) = gcd(3,0) So 231x + 60y = 3. 231 = 60*3 + 51, 60 = 51*1 + 9. 51 = 9*5 + 6. 9 = 6*1 + 3. 6 = 3*2. Then going back up 3*1 + 0*0, 6*0 + 3*1, 6*0 + (96*1)*1, 9*1 6*1. 9*1 (519*5), 9*6 51*1, (6051)*6 51*1, 60*6 51*7. 60*6 (231 60*3) * 7, 60*27 231*7, so x = (6051)*6 51*1, 60*6 51*7....
View
Full
Document
This note was uploaded on 01/09/2012 for the course CSE 101 taught by Professor Staff during the Spring '08 term at UCSD.
 Spring '08
 staff
 Algorithms

Click to edit the document details