This preview shows pages 1–4. Sign up to view the full content.
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
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.
 Spring '10
 fleck

Click to edit the document details