110 likes | 208 Views
GCD The Design and Analysis of Computer Algorithms 8.8 Greatest common divisors and Euclid’s algorithm. 報告者: 張書豪. Outline. Half GCD Example. HGCD Algorithm. procedure HGCD(a 0 ,a 1 ) : If DEG(a 1 ) ≦DEG(a 0 )/2 then else begin
E N D
GCDThe Design and Analysis of Computer Algorithms 8.8 Greatest common divisors and Euclid’s algorithm 報告者:張書豪
Outline • Half GCD • Example
HGCD Algorithm procedure HGCD(a0,a1): If DEG(a1) ≦DEG(a0)/2 then else begin let a0=b0xm+c0, where m= and DEG(c0) <m; let a1=b1xm+c1,where DEG(c1)<m; R←HGCD(b0,b1);
f ← d modulo e; end
Example HGCD(a0,a1) a0(x)=x5+x4+x3+x2+x+1 a1(x)=x4-2x3+3x2-x-7 由a0=b0xm+c0與a1=b1xm+c1,可得到 b0= x3+x2+x+1, c0=x+1, b1=x2-2x+3, c1=-x-7, HGCD(x3+x2+x+1, x2-2x+3) DEG(b1) >DEG(b0)/2
再做HGCD(b0,b1) a0(x)= x3+x2+x+1, a1(x)=x2-2x+3, 由a0=(x2+x+1)x1+1, a1=(x-2)x1+3,可得到 b0= x2+x+1, c0=1, b1=x-2, c1=3, 此時DEG(b1) =DEG(b0)/2 R←HGCD(b0,b1)
可得d= x3+x2+x+1,e= x2-2x+3,f=d mod e=4x-8 m/2=3/2下限為1,e=(x-2)x+3,f=4(x)-8, g0=x-2,g1=4x0,DEG(0)=DEG(1)/2的下限 S←HGCD(g0,g1)
R←HGCD(b0,b1) d= x4-2x3+3x2-x-7 e= 4x3-7x2+11x+22 f ← d modulo e;
b0=4x3-7x2+11x+22, b1=-3/16x2-93/16x-45/8, DEG(2)>DEG(3)/2下限 →b0=(4x2-7x+11)x+22 b1=(-3/16x-93/16)x-45/8 DEG(1)=DEG(2)/2