Extended Euclidean algorithm

Learn Algorithms · 2:48

Listen on 93

Lyrics

[Verse 1]
Two numbers standing side by side
Need their greatest common factor to find
Euclid showed us the way back then
But extended version goes beyond again
Start with coefficients one and zero
Swap them round like a mathematical hero
Track the linear combination
Through each step of the equation

[Chorus]
Back substitute, don't lose the thread
Keep the old remainder, move ahead
X and Y will show the way
Bezout coefficients on display
Extended Euclidean, step by step
Linear combo, don't forget
GCD plus the magic pair
Integers that take you there

[Verse 2]
Dividend divided by the quotient clean
Remainder tells us what the next step means
But now we track the extra data
Two more columns in our algebra
New X equals old X minus quotient times the current
New Y follows same pattern, never different
Until remainder hits zero flat
That's when we know where we're at

[Chorus]
Back substitute, don't lose the thread
Keep the old remainder, move ahead
X and Y will show the way
Bezout coefficients on display
Extended Euclidean, step by step
Linear combo, don't forget
GCD plus the magic pair
Integers that take you there

[Bridge]
Modular arithmetic needs this tool
Inverse elements follow the rule
When A times X equals one mod M
Extended Euclid finds X again
Cryptography depends on this
RSA won't work if you miss
The inverse calculation game
Extended algorithm stakes the claim

[Verse 3]
Table method keeps it organized neat
Quotient remainder X and Y complete
Work your way down row by row
Watch the pattern start to flow
Last non-zero remainder found
That's your GCD renowned
X and Y in final line
Bezout identity by design

[Chorus]
Back substitute, don't lose the thread
Keep the old remainder, move ahead
X and Y will show the way
Bezout coefficients on display
Extended Euclidean, step by step
Linear combo, don't forget
GCD plus the magic pair
Integers that take you there

[Outro]
A times X plus B times Y
Equals GCD, that's no lie
Extended algorithm shows the proof
Mathematical absolute truth

← Edmonds-Karp | Modular exponentiation →