Module 2 : GCD Computation

Lecture 2 : Euclid's Algorithm

EUCLID (a, b)
1. if b=0
2. then return (a)
3. else return(EUCLID(b, a mod b))

Lemma: If a > b 1 and the invocation EUCLID(a, b) performs k 1 calls
then a Fk+2 and b Fk+1

Proof: (By induction)

Basis: Let k=1, we know a > b 1
b F2 = 1 (here k+1=2)

Since a > ba 2 ⇒ a F3 (here k+2=3)

If a > b initially then this property a > b is maintained at each recursive invocation in EUCLID ( a , b ) algorithm, since b > a mod b always.

NOTE: Since a mod b < b The invariant 1st argument > 2nd argument of EUCLID's algorithm is maintained during each iteration.

Inductive Hypothesis: Assume the result holds for # of invocations k -1

Inductive proof: Let EUCLID ( a , b ) makes k invocations

                        ⇒ EUCLID ( b , a mod b ) makes ( k -1) invocation

From our inductive hypothesis:

b F ( k -1)+2 , a mod b F ( k -1)+1

Therefore b F k +1 , a mod b F k

We know, a = * b + a mod b (where = Floor ( a ))

1 a b + a mod b .

Since a mod b F k we have a F k +1 + Fk a F k +2 .

Lame’s Theorem: For any integer k 1 if a > b 1 and if b < Fk +1 then EUCLID (a, b) makes fewer than k recursive calls gcd ( Fk +1, Fk ) = gcd (Fk, Fk -1) = … = gcd (1,0) = 1

Therefore # of recursive invocation = k-1

This shows that the bound k-1 is tight.

Fk / Fk -1 Φ[Golden Ratio Φ =]

To represent Fk, # of bits required = k

Therefore for two β bit numbers running time complexity of EUCLID is O (β)