2.5.8 · HinglishNumber Theory (Intermediate)

Extended Euclidean algorithm

2,005 words9 min readRead in English

2.5.8 · Maths › Number Theory (Intermediate)


Derivation from First Principles

Regular Algorithm Kaise Kaam Karta Hai

se shuru karo. Euclidean algorithm ek sequence produce karta hai:

Last non-zero remainder hi hai.

Coefficients Ko Backwards Track Karna

Second-to-last equation se: .

ka expression upar wali line se substitute karo, phir ka, aur aisa karte karte wapis aur tak jaao. Yeh substitution reveal karta hai ki kuch integers ke liye.

The Forward (Efficient) Method

Backtrack karne ki jagah, har step par coefficients maintain karo jaise ki .

Base cases:

Recurrence: se, humein milta hai:

Yeh step kyun? Har remainder pichle do ka linear combination hota hai. Agar hum jaante hain pichle dono ko aur ke terms mein kaise likhte hain, toh naye ko bhi usi tarah likh sakte hain.


Worked Examples

Step
0 56 1 0
1 15 0 1
2 56 15 3 11 1 0 0 1
3 15 11 1 4 0 1 1 -3
4 11 4 2 3 1 -1 -3 4
5 4 3 1 1 -1 3 4 -11
6 3 1 3 0

Result: , with , .

Verification: . ✓

Yeh step kyun? Har row naya remainder compute karta hai aur recurrence use karke coefficients update karta hai. Jab ho jaata hai, pichli row answer deti hai.


Step
0 240 1 0
1 46 0 1
2 240 46 5 10 1 - 5·0 = 1 0 - 5·1 = -5
3 46 10 4 6 0 - 4·1 = -4 1 - 4·(-5) = 21
4 10 6 1 4 1 - 1·(-4) = 5 -5 - 1·21 = -26
5 6 4 1 2 -4 - 1·5 = -9 21 - 1·(-26) = 47
6 4 2 2 0

Result: , with , .

Check: . ✓


Common Mistakes


Applications

  1. Modular Inverse: find karne ke liye (jab ho), aur par Extended Euclidean run karo. Coefficient jo satisfy karta hai woh inverse hai: .

  2. Linear Diophantine Equations: solve karne ke liye, pehle find karo. Agar , ka multiple nahi hai, toh koi solution exist nahi karta. Warna, Bézout coefficients ko scale karo: agar hai, toh aur ek particular solution hai.

  3. RSA Cryptography: Private key compute karna jaise ki Extended Euclidean Algorithm use karta hai.


Diagram

Figure — Extended Euclidean algorithm

Recall Feynman: Ek 12-saal ke bacche ko samjhao

Socho tumhare paas coins ki do dher hain, maano 56 aur 15. Regular Euclidean algorithm bilkul waisa hai jaise baar baar chhoti dher ko badi se hatate rehna jab tak tumhare paas sabse badi dher na bache jo dono ko divide kare (yeh gcd hai).

Ab, Extended version poochta hai: "Kya main original dono dher ke sizes ko addition aur subtraction se combine karke exactly yeh gcd bana sakta hoon?" Jawab hamesha haan hota hai! Algorithm ek running tally rakhta hai: "Ab tak, yeh remainder pehli dher ki __ copies aur doosri dher ki ___ copies se bana hai (jahan negative ka matlab hai hum subtract kar rahe hain)."

Ant mein, tumhe pata hota hai exactly kitni original dher add/subtract karni hai gcd paane ke liye. Wahi magic formula hai aur yeh number theory mein har jagah use hota hai!



Connections

  • Euclidean Algorithm — "non-extended" version jo sirf find karta hai
  • Bézout's Identity — theorem jo integer solutions guarantee karta hai
  • Modular Multiplicative Inverse — Extended Euclidean se milta hai jab ho
  • Linear Diophantine Equations — Bézout coefficients scale karke solve hote hain
  • Chinese Remainder Theorem — apni construction mein modular inverses use karta hai
  • RSA Algorithm — private key calculation Extended Euclidean par depend karta hai

#flashcards/maths

Extended Euclidean Algorithm kya compute karta hai? :: Yeh aur integers compute karta hai jaise ki (Bézout's identity).

Coefficient recurrence ke base cases kya hain?
for ke liye, aur for ke liye.
Extended Euclidean Algorithm mein ki recurrence kya hai?
, jahan step par quotient hai.

Extended Euclidean use karke ka modular inverse modulo kaise find karte hain? :: aur par Extended Euclidean run karo. Agar hai, toh se coefficient hi inverse hai.

Linear Diophantine equation ke integer solutions kab hote hain?
Tabhi aur sirf tabhi jab , ko divide kare.

Agar hai, toh aur kya hain? :: , , kyunki aur .

Hum gcd aur coefficients ke liye second-to-last row kyun use karte hain?
Last remainder hamesha 0 hota hai. gcd last non-zero remainder hota hai, jo second-to-last row mein appear hota hai.
Bézout's Identity kya hai?
Kisi bhi integers ke liye (jo dono zero na hon), integers exist karte hain jaise ki .

Concept Map

computes

tracks coefficients

finds x and y

linear combination of

expressed via

gives coefficients

start

final row is

enables

last nonzero equals

Euclidean algorithm

gcd of a and b

Extended Euclidean algorithm

Bezout identity ax + by = gcd

Each remainder r_i

a and b

Recurrence r_i = r_i-2 - q_i r_i-1

x_i = x_i-2 - q_i x_i-1

Base cases 1,0 and 0,1

Modular inverses, RSA, Diophantine