cse101_9_30_11

cse101_9_30_11 - 1. Greatest common divisor a. Function...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the 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 + (9-6*1)*1, 9*1 6*1. 9*1 (51-9*5), 9*6 51*1, (60-51)*6 51*1, 60*6 51*7. 60*6 (231 60*3) * 7, 60*27 231*7, so x = (60-51)*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.

Page1 / 2

cse101_9_30_11 - 1. Greatest common divisor a. Function...

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

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