The extended Euclidean Algorithm allows us to calculate gcd(a,b), and solve the Linear Diophantine Equation for gcd(a,b) in terms of a and b, where
ax+by=gcd(a,b)
We know that an answer always exists from Bezout’s Lemma.
LCM and GCD
Recursive (implements EEA)
Iterative (i think the way we learned in class), faster than recursive above
There is something very important to observe about the table. If we are computing gcd(a,b), then for each row of the table we have axi+byi=ri
Input: Integers a, b with a≥b>0Initialize: Construct the table with four columns so that
the columns are labeled x,y,rand q,
the first row in the table is (1,0,a,0),
the second row in the table is (0,1,b,0).
Repeat: For i≥3,
qi←⌊ri−1ri−2⌋
Rowi←Rowi−2−qiRowi−1
Stop: When ri=0Output: Set n=i−1. Then gcd(a,b)=rn, and s=xn and t=yn are a certificate of correctness.