Table of contents
1.
Introduction:
Basic Euclidean Algorithm for GCD
1.
Extended Euclidean Algorithm
2.
How Does the Extended Euclidean Algorithm Work?
3.
How Is the Extended Euclidean Algorithm Useful?
4.
Frequently Asked Questions
4.1.
What is the formula for the Euclidean Algorithm?
4.2.
What is the LCM of the Euclidean Algorithm?
4.3.
What is HCF by Euclid's Algorithm?
5.
Conclusion
Last Updated: Nov 12, 2024
Easy

Euclidean Algorithm

Author NISHANT RANA
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction:

The Euclidean Algorithm is a number theory cornerstone with applications far beyond mathematics. Originally devised by the ancient Greek mathematician Euclid, this algorithm provides an efficient way to find the greatest common divisor (GCD) of two integers—a problem that arises in cryptography to computer science, engineering, and even music theory. By breaking down large numbers through a systematic process of repeated division, the Euclidean Algorithm stands out as both powerful and accessible, enabling us to simplify complex calculations and understand relationships between numbers. In this blog, we'll explore how the Euclidean Algorithm works.

Euclidean Algorithm

Read More - Time Complexity of Sorting Algorithms, Prims and Kruskal Algorithm and Euclid GCD Algorithm

Basic Euclidean Algorithm for GCD

The Basic Euclidean Algorithm is a simple yet powerful method to find the Greatest Common Divisor (GCD) of two numbers. It works on the principle that the GCD of two numbers also divides their difference.

Here's how it works:

  1. Take two numbers a and b
  2. Divide a by b to get quotient q and remainder r
  3. If r = 0, b is the GCD
  4. If r ≠ 0, set a = b and b = r, then repeat from step 2

For example, let's find GCD(48, 18):

48 = 2 × 18 + 12
18 = 1 × 12 + 6
12 = 2 × 6 + 0

Therefore, GCD(48, 18) = 6

Extended Euclidean Algorithm

The Extended Euclidean Algorithm is an extension of the basic algorithm that, in addition to the GCD, also finds the coefficients of Bézout's identity. That is, it finds integers x and y such that:

ax + by = gcd(a,b)

This algorithm is particularly useful in:

  • Finding multiplicative inverses in modular arithmetic
  • Solving linear Diophantine equations
  • Public key cryptography (RSA algorithm)

Here's how it works:

  1. Initialize:
    • r1 = a, r2 = b
    • s1 = 1, s2 = 0
    • t1 = 0, t2 = 1
  2. While r2 > 0:
    • Calculate quotient: q = r1/r2
    • Update remainders: r = r1 - q×r2
    • Update coefficients: s = s1 - q×s2, t = t1 - q×t2
    • Update values for next iteration

For example, let's find GCD(48, 18) and coefficients:

48 = 2 × 18 + 12
18 = 1 × 12 + 6
12 = 2 × 6 + 0
 Working backwards:
6 = 18 - 1(12)
6 = 18 - 1(48 - 2×18)
6 = 3×18 - 1×48

Therefore: 3×18 - 1×48 = 6 The coefficients are x = -1 and y = 3

How Does the Extended Euclidean Algorithm Work?

The Extended Euclidean Algorithm not only finds the greatest common divisor (GCD) of two integers but also expresses the GCD as a linear combination of these integers. In other words, for integers aaa and bbb, it finds integers xxx and yyy such that: a⋅x+b⋅y=GCD(a,b)a \cdot x + b \cdot y = \text{GCD}(a, b)a⋅x+b⋅y=GCD(a,b)

Example:
Let's find the GCD of 30 and 18 and express it as a linear combination.

First, apply the Euclidean Algorithm:

  • 30=18×1+12
  • 18=12×1+6
  • 12=6×2+0

Now, backtrack to express 6 as a combination of 30 and 18:

  • 6=18−12×1
  • Substitute 12=30−18 into the equation:
    6=18−(30−18)×1=18×2−30

Therefore, x=−1 and y=2, giving us 6=−1×30+2×18.

How Is the Extended Euclidean Algorithm Useful?

The Extended Euclidean Algorithm is crucial in fields like cryptography and number theory, particularly for solving Diophantine equations and finding modular inverses. In cryptography, it helps calculate modular inverses in algorithms like RSA, enabling secure communication. It’s also widely used for solving linear congruences, making it valuable in systems involving modular arithmetic. Through its ability to find coefficients in linear combinations, the Extended Euclidean Algorithm extends beyond basic GCD calculation, proving essential for practical applications requiring precision in mathematical problem-solving.

Frequently Asked Questions

What is the formula for the Euclidean Algorithm?

The Euclidean Algorithm uses the formula:
GCD(a, b) = GCD(b, a mod b)
This formula applies repeatedly, replacing aaa with bbb and bbb with amod  ba \mod bamodb, until b=0b = 0b=0. The last non-zero remainder is the GCD.

What is the LCM of the Euclidean Algorithm?

The Least Common Multiple (LCM) of two numbers aaa and bbb can be found through their GCD by using the formula:
LCM(a, b) = (a × b) / GCD(a, b)
This formula connects LCM and GCD, making calculation efficient.

What is HCF by Euclid's Algorithm?

The Highest Common Factor (HCF), or GCD, by Euclid’s Algorithm is found by repeatedly applying the Euclidean Algorithm to two numbers until reaching a remainder of zero. The last non-zero remainder is the HCF of the two numbers.

Conclusion

In this blog, we have covered Euclidean Algorithm. The Euclidean Algorithm is a timeless tool that showcases the power of simplicity in mathematics. From its origins in ancient Greece to its continued relevance in modern-day applications, this algorithm remains one of the most efficient methods for finding the greatest common divisor (GCD) of two numbers. By understanding its process and derivations, like the connection to LCM, we gain deeper insights into number relationships and problem-solving techniques. 

If you want to learn more about such Algorithms and practice some questions requiring you to take your basic knowledge a notch higher, you can visit our Guided Path.

Also Read - Kadanes Algorithm

Until then, All the best for your future endeavors, and Keep Coding.

Live masterclass