Euclidean Algorithm
Context: FIT1058_MOC · computes gcd by repeated reduction · subtraction sped up to remainder · extended to find Bézout coefficients
Quick Revision
- 🎯 Objective: compute by iterating ➔ stop when , output .
- 📦 Core Components: reduction ➔ base case ➔ quotient saved for Extended Euclidean Algorithm.
- ⚡ Key Constraint: remainder form collapses subtractions into one ; terminates as strictly decreases.
📝 Core
1. The Reduction (Subtraction → Remainder)
- Identity ➔ (Greatest Common Divisor reduction theorem).
- Speed-up ➔ replace repeated with a single ➔ .
- Base case ➔ ⟹ output .
2. Why It Works & Halts
- Correctness ➔ each step preserves the pair’s common divisors ⟹ final divisor = original .
- Termination ➔ second argument strictly decreases and stays ⟹ must reach .
- Quotient saved ➔ recorded ➔ reused by Extended Euclidean Algorithm for Bézout .
Key identities:
⚖️ Core Decision Matrix
| Form | Step cost | When it hurts |
|---|---|---|
| Subtraction | subtractions to one remainder | huge quotient ⟹ many steps |
| Remainder | one modulo per step | none — the efficient form |
| Extended | remainder + a Bézout triple | slightly more bookkeeping |
When It Flips: the remainder form runs in divisions (worst case: consecutive Fibonacci numbers). It is the standard test for Coprimality () and, extended, computes modular inverses.
📊 Exam Execution Trace
Manual Execution Trace
, iterating :
| Step / State | ||||
|---|---|---|---|---|
| 0 (Init) | 252 | 198 | — | — |
| 1 | 252 | 198 | 1 | 54 |
| 2 | 198 | 54 | 3 | 36 |
| 3 | 54 | 36 | 1 | 18 |
| 4 | 36 | 18 | 2 | 0 → |
⚠️ Common Mistakes
- 💡 Keep going until , don’t stop at the first small remainder ➔ the answer is the last divisor, not the last remainder; and record if the Bézout coefficients are wanted.
🧠 Active Recall
Why is the remainder form faster than the subtraction form, and why does it terminate?
- Hint: One modulo = many subtractions; monotone decrease.
Answer
- Short answer: does all subtractions at once; the second argument strictly decreases while staying , so it reaches .
- Why: Divisor-preserving ➔ every step keeps the pair’s common divisors, so the final divisor is the original .
Trace the Euclidean Algorithm on .
- Hint: Iterate remainders to divisibility.
Answer
- Short answer: , , , ; ⟹ output .
- Why: Last divisor ➔ the answer is the divisor at the base case , not the last non-zero remainder computed mid-loop.
What does the extended algorithm add, and why keep the quotient ?
- Hint: Bézout bookkeeping.
Answer
- Short answer: It returns with (Integer Linear Combination).
- Why: Back-substitution ➔ each is reused to unwind the remainders into the coefficients — the basis of modular inverses.