THE EUCLIDEAN ALGORITHM The Algorithm - Reed …people.reed.edu/~jerry/131/eucalg.pdfThus, nally,...

2

Click here to load reader

Transcript of THE EUCLIDEAN ALGORITHM The Algorithm - Reed …people.reed.edu/~jerry/131/eucalg.pdfThus, nally,...

Page 1: THE EUCLIDEAN ALGORITHM The Algorithm - Reed …people.reed.edu/~jerry/131/eucalg.pdfThus, nally, our tightest integer upper bound on the number nof steps for the Euclidean algorithm

THE EUCLIDEAN ALGORITHM

1. The Algorithm

The given inputs are x, y ∈ Z>0 with y < x.

• (Initiate) Set

a, b, α, β, γ, δ = x, y, 1, 0, 0, 1.

• (Iterate) While b > 0, we have a = qb+ r where 0 ≤ r < b; set

a, b, α, β, γ, δ = b, r, γ, δ, α− qγ, β − qδ,and return to this step.

• (Terminate) Return a, α, β. These outputs satisfy the conditions

gcd(x, y) = a = αx+ βy.

For example, to compute gcd(986, 357) the algorithm proceeds as follows:

a b α β γ δ calculation for next line986 357 1 0 0 1 986 = 2 · 357 + 272357 272 0 1 1 −2 357 = 1 · 272 + 85272 85 1 −2 −1 3 272 = 3 · 85 + 1785 17 −1 3 4 −11 85 = 5 · 1717 0 4 −11

Thus gcd(986, 357) = 17 = 4 · 986− 11 · 357.

To see that the algorithm works as claimed, note first that after the initiationstep,

gcd(x, y) = gcd(a, b), a = αx+ βy, b = γx+ δy.

Each iteration preserves these conditions since

gcd(anew, bnew) = gcd(bold, aold − qbold)

= gcd(aold, bold),

anew = bold

= γoldx+ δoldy

= αnewx+ βnewy,

bnew = aold − qbold= αoldx+ βoldy − q(γoldx+ δoldy)

= (αold − qγold)x+ (βold − qδold)y

= γnewx+ δnewy.

The algorithm terminates when b = 0, at which point

gcd(x, y) = gcd(a, b) = a = αx+ βy.

(Note: Because the point here is to check the algorithm, the mathematical assertion“gcd(anew, bnew) = gcd(bold, aold−qbold) = gcd(aold, bold)” was made quickly in this

1

Page 2: THE EUCLIDEAN ALGORITHM The Algorithm - Reed …people.reed.edu/~jerry/131/eucalg.pdfThus, nally, our tightest integer upper bound on the number nof steps for the Euclidean algorithm

2 THE EUCLIDEAN ALGORITHM

setting, but mathematically it is the heart of the matter. The point is that each ofanew, bnew lies in the ideal generated by aold and bold, and conversely.)

2. Analysis

The algorithm generates a succesion of remainders

r−1 = x

r0 = y

rk = rk−2 − qkrk−1, k = 1, · · · , nwith

r−1 > r0 > r1 > · · · > rn−1 > rn = 0.

Here n is the number of steps that the algorithm takes to compute gcd(x, y).Thus we have

rn−1 ≥ 1 = F2

rn−2 ≥ 2 = F3

rn−3 ≥ rn−2 + rn−1 ≥ F4

· · ·y = r0 = rn−n ≥ Fn+1.

Another way to express this is as an implication, to which we concatenate a secondimplication in consequence of k being an integer,

Fk > y =⇒ k > n+ 1 =⇒ k ≥ n+ 2.

Or, by a small reindexing,

Fk+2 > y =⇒ k ≥ n.A lemma that we have proved, on page 72 of our textbook, says that Fk+2 > ϕk

for k ≥ 1. So now we haveϕk > y =⇒ k ≥ n.

Equivalently,k > logϕ(y) =⇒ k ≥ n,

ork ≥ dlogϕ(y)e =⇒ k ≥ n.

Thus, finally, our tightest integer upper bound on the number n of steps for theEuclidean algorithm to compute gcd(x, y) where 0 < y < x is

dlogϕ(y)e ≥ n.

For the example earlier, the upper bound on the number of steps is dlogϕ(357)e =13, while the actual number of steps is 4.