trekhleb / javascript-algorithms

📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings
MIT License
185.25k stars 29.89k forks source link

Added Extended Euclidean Algorithm #905

Open vishalt12345 opened 2 years ago

vishalt12345 commented 2 years ago

While the Euclidean algorithm calculates only the greatest common divisor (GCD) of two integers a and b, the extended version also finds a way to represent GCD in terms of a and b, i.e. coefficients x and y for which: a x + b y = gcd(a, b). This is extremely useful in the application of the chinese remainder theorem and calculating modular inverses.