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

Info iconThis 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
Background image of page 1

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

View Full DocumentRight 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
Background 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)
Background image of page 3

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

View Full DocumentRight Arrow Icon
Background 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

This note was uploaded on 12/24/2010 for the course CS CS 173 taught by Professor Fleck during the Spring '10 term at University of Illinois, Urbana Champaign.

Page1 / 4

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

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

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