MIT6_042JS10_lec14

MIT6_042JS10_lec14 - Euclidean Algorithm Mathematics for...

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

View Full Document Right Arrow Icon
1 Albert R Meyer, March 5, 2010 Mathematics for Computer Science MIT 6.042J/18.062J State Machines: Derived Variables lec 5F.1 Albert R Meyer, March 5, 2010 Euclidean Algorithm -- for GCD(a, b) 1. x ::= a, y ::= b. 2. If y = 0, return x & terminate; 3. else simultaneously: (x, y) := (y, rem(x,y)) 4. Go to step 2. lec 5F.2 Albert R Meyer, March 5, 2010 GCD correctness Example: GCD(662,414) = GCD(414, 248) since rem(662,414) = 248 = GCD(248, 166) since rem(414,248) = 166 = GCD(166, 82) since rem(248,166) = 82 = GCD(82, 2) since rem(166,82) = 2 = GCD(2, 0) since rem(82,2) = 0 return value: 2 lec 5F.3 Albert R Meyer, March 5, 2010 Euclid Algorithm State Machine States ::= start ::= (a,b) state transitions defined by (x,y) (y, rem(x,y)) for y 0 lec 5F.4 Albert R Meyer, March 5, 2010 GCD correctness preserved invariant P(x,y): [gcd(a,b) = gcd(x,y)] lec 5F.5 Albert R Meyer, March 5, 2010 transitions: (x, y) (y, rem(x, y)) Proof: x = qy + rem. any divisor of 2 of these 3
Background image of page 1

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

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

{[ snackBarMessage ]}

Page1 / 5

MIT6_042JS10_lec14 - Euclidean Algorithm Mathematics for...

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