This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full 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
 Spring '10
 fleck
 Greatest common divisor, Euclidean algorithm, gcd, 2,300 year

Click to edit the document details