am_lect_10 - x:= a y:= b while y ≠ r:= x mod y x:= y y:=...

Info icon This preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Quiz 1 Start time: 9:00am End time: 9:20am
Image of page 1

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

View Full Document Right Arrow Icon
GCD Recall that gcd ( a , b ) is the greatest common divisor of a and b For any non-zero integer n , gcd ( n , 0) = n gcd (0, 0) is undefined If a Z , b Z + and a = bq + r then gcd ( a , b ) = gcd ( r , b ) Proof : Suppose gcd ( a , b ) = k Then n Z , a = kn and m Z , b = km So kn = ( km ) q + r and hence r = k ( n mq ) Thus k is a common divisor of b and r Suppose gcd ( b , r ) = t > k Since t b and t r then t ( bq + r ) So t is a common divisor of a and b , a contradiction (since t > k ) See 1pm lecture notes for a different proof
Image of page 2
Euclidean algorithm for GCD Corollary : For positive integers a and b , gcd ( a , b ) = gcd ( b , a mod b ) A 2,300 year old algorithm (pseudocode): procedure gcd(a, b: positive integers)
Image of page 3

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

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: x := a y := b while y ≠ r := x mod y x := y y := r return x Example : gcd (105, 252) x y r = x mod y 105 252 105 252 105 42 105 42 21 42 21 21 = 21 Recursive algorithm for GCD Recursion is a technique for reducing a big problem into one or more similar, smaller , problems — with a base case to handle the simplest problems procedure gcd(a, b: positive integers) r := a mod b if (r = 0) return b else return gcd(b, r) Example : gcd (105, 252) a b r = a mod b 105 252 105 252 105 42 105 42 21 42 21 21 = 21...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern