euclidean algorithm for gcd l.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Euclidean Algorithm for GCD PowerPoint Presentation
Download Presentation
Euclidean Algorithm for GCD

Loading in 2 Seconds...

play fullscreen
1 / 9

Euclidean Algorithm for GCD - PowerPoint PPT Presentation


  • 466 Views
  • Uploaded on

Euclidean Algorithm for GCD. CSCI 284/162 Spring 2007 GWU. Euclidean Algorithm considered first non-trivial algorithm. Algorithm_gcd(m, a) /* m > a */ (X, Y) := (m, a) /* Initialize */ while (Y  0) (X, Y) := (Y, X rem Y) return(X) Works because: gcd (X, Y) = gcd(Y, X rem Y)

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Euclidean Algorithm for GCD' - Patman


Download Now An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
euclidean algorithm for gcd

Euclidean Algorithm for GCD

CSCI 284/162

Spring 2007

GWU

euclidean algorithm considered first non trivial algorithm
Euclidean Algorithmconsidered first non-trivial algorithm

Algorithm_gcd(m, a) /* m > a */

(X, Y) := (m, a) /* Initialize */

while (Y0) (X, Y) := (Y, X rem Y)

return(X)

Works because:

gcd (X, Y) = gcd(Y, X rem Y)

gcd(X, Y) = Y if Y|X

Stops because:

(X, Y) always decreasing and non-negative

CS284-162/Spring07/GWU/Vora/ Euuclidean Algorithm for GCD

slide3
Try

gcd(17, 101)

gcd(57, 93)

CS284-162/Spring07/GWU/Vora/ Euuclidean Algorithm for GCD

theorem gcd x y gcd y x rem y x y 0
Theorem: gcd(X, Y) = gcd(Y, X rem Y); X, Y0

Proof:

Let X rem Y = r  r = X – qY for integer q

Consider a factor g of X and Y

g|X and g|Y

  • X = q1g, Y = q2g, for some integers q1 and q2
  • r = g(q1 – qq2)
  • g|Y and g|r

CS284-162/Spring07/GWU/Vora/ Euuclidean Algorithm for GCD

theorem gcd x y gcd y x rem y x y 05
Theorem: gcd(X, Y) = gcd(Y, X rem Y); X, Y0

Proof contd:

Consider a factor h of Y and r

h|Y and h|r

  • Y = q3h, r = q4h for some integers q3 and q4
  • X = h(q4 + qq3)
  • h|Y and h|X

Note: all integers are factors of 0, see, for example, example 2.80 in Chapter 2, Handbook of Applied Cryptography, http://www.cacr.math.uwaterloo.ca/hac/about/chap2.pdf

CS284-162/Spring07/GWU/Vora/ Euuclidean Algorithm for GCD

theorem gcd x y gcd y x rem y proof contd
Theorem: gcd(X, Y) = gcd(Y, X rem Y)Proof contd.

Hence all common factors of X and Y are common factors of Y and r and vice versa.

Hence, in particular, the pair (X, Y) and the pair (Y, r) have the same gcd.

CS284-162/Spring07/GWU/Vora/ Euuclidean Algorithm for GCD

euclidean algorithm correctness proof
Euclidean Algorithm: Correctness Proof

Theorem: Algorithm_gcd (m, a) returns gcd(m, a)

Proof: Let the ith update of (X, Y) be denoted (Xi Yi)

Then

(m, a) = (X0 Y0)

and the algorithm returns XN if the algorithm performs N (a finite number) updates.

CS284-162/Spring07/GWU/Vora/ Euuclidean Algorithm for GCD

euclidean algorithm correctness proof contd
Euclidean Algorithm: Correctness Proof contd.

From previous theorem, gcd (X, Y) = gcd(Y, X rem Y)

 gcd(m, a) = gcd(X0 Y0) = gcd(X1 Y1) = gcd(X2 Y2) = …. gcd(XN-1 YN-1)

YN-1|XN-1

  • gcd(XN-1 YN-1) = YN-1 = XN = Algorithm_gcd (m, a)

Hence gcd(m, a) = Algorithm_gcd (m, a)

If N finite

CS284-162/Spring07/GWU/Vora/ Euuclidean Algorithm for GCD

euclidean algorithm correctness proof contd9
Euclidean Algorithm: Correctness Proof contd.

a=Y0 > Y1 > Y2 > …. > YN-1 > YN = 0

As Y decreases by at least 1 each iteration

N a

N is finite.

CS284-162/Spring07/GWU/Vora/ Euuclidean Algorithm for GCD