Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 GCD The Design and Analysis of Computer Algorithms 8.8 Greatest common divisors and Euclid’s algorithm 報告者:張書豪.

Similar presentations


Presentation on theme: "1 GCD The Design and Analysis of Computer Algorithms 8.8 Greatest common divisors and Euclid’s algorithm 報告者:張書豪."— Presentation transcript:

1 1 GCD The Design and Analysis of Computer Algorithms 8.8 Greatest common divisors and Euclid’s algorithm 報告者:張書豪

2 2 Outline Half GCD Example

3 3 HGCD Algorithm procedure HGCD(a 0,a 1 ) : If DEG(a 1 ) ≦ DEG(a 0 )/2 then else begin let a 0 =b 0 x m +c 0, where m= and DEG(c 0 ) < m ; let a 1 = b 1 x m + c 1,where DEG(c 1 )<m ; R←HGCD(b 0,b 1 ) ;

4 4 f ← d modulo e ; end

5 5 Example HGCD(a 0,a 1 ) a 0 (x) = x 5 +x 4 +x 3 +x 2 +x+1 a 1 (x) = x 4 -2x 3 +3x 2 -x-7 由 a 0 =b 0 x m +c 0 與 a 1 = b 1 x m + c 1, 可得到 b 0 = x 3 +x 2 +x+1, c 0 =x+1, b 1 =x 2 -2x+3, c 1 =-x-7, HGCD(x 3 +x 2 +x+1, x 2 -2x+3) DEG(b 1 ) > DEG(b 0 )/2

6 6 再做 HGCD(b 0,b 1 ) a 0 (x) = x 3 +x 2 +x+1, a 1 (x) = x 2 -2x+3, 由 a 0 =(x 2 +x+1)x 1 +1, a 1 = (x-2)x 1 +3, 可得到 b 0 = x 2 +x+1, c 0 =1, b 1 =x-2, c 1 =3, 此時 DEG(b 1 ) = DEG(b 0 )/2 R←HGCD(b 0,b 1 )

7 7 可得 d= x 3 +x 2 +x+1,e= x 2 -2x+3,f=d mod e=4x-8 m/2=3/2 下限為 1,e=(x-2)x+3,f=4(x)-8, g 0 =x-2,g 1 =4x 0,DEG(0)=DEG(1)/2 的下限 S←HGCD(g 0,g 1 )

8 8 R←HGCD(b 0,b 1 ) d= x 4 -2x 3 +3x 2 -x-7 e= 4x 3 -7x 2 +11x+22 f ← d modulo e ;

9 9 e=(4x 2 -7x+11)x 1 +22,

10 10

11 11 b 0 =4x 3 -7x 2 +11x+22, b 1 =-3/16x 2 -93/16x-45/8, DEG(2)>DEG(3)/2 下限 →b 0 =(4x 2 -7x+11)x+22 b 1 =(-3/16x-93/16)x-45/8 DEG(1)=DEG(2)/2


Download ppt "1 GCD The Design and Analysis of Computer Algorithms 8.8 Greatest common divisors and Euclid’s algorithm 報告者:張書豪."

Similar presentations


Ads by Google