Skip to main content

Euclidian Algorithm(Math)

Hi all !
I,m here again with some interesting article. It's not about programming or databases this time.
It's algorithm. Actually It's Math. We all know it as Euclidian Algorithm(Euclid in Math).


Let's start this then !!!


The "Euclidian algorithm" is an algorithm that finds the greatest common divisor of 2 numbers.Discovered by Euclid in the mid 4th century BC, it's referred to as the world's oldest algorithm.



As an example, let's consider the largest common divisor of 1112 and 695.


With the usual method, we factorize the 2 numbers into prime numbers.



and the greatest common divisor(GCD) from the prime numbers they share.
Now we know that the greatest common divisor for 1112 and 695 is 139.
However, with this method, the larger the 2 numbers get, the more difficult prime factorization becomes.With Euclidian Algorithm, we can find greatest common divisors more efficiently.





Before we Enter an explanation of the Euclidian Algorithm,let's explain the mod operation.The mod operation is an operation that finds the remainder of a division.For A mod B, we get C, the remainder of A divided by B.





Let's show some example operations using concrete numbers.





Now ,let's take a look at the Euclidian algorithm in action.



First we find the remainder of the larger number divided by the smaller number.
in other words we will carry out a mod operation with the larger and smaller numbers.



The result of the division found 417 to be remainder.

This time , we carry out a mod operation with the previous divisor,695 ,and the previous remainder, 417.

We got 278


We repeat the same operation , carrying out a mod operation with 417 and 278.



We got 139



We carry out a mod operation with 278 and 139.



We got 0.
In other words,278 is divisible by 139.




When the remainder is 0, the divisor of the last operation, 139, is found to be the greatest common divisor of 1112 and 695.
How is the Euclidian algorithm able to find the greatest common divisor?
Let's consider that question using the diagram.



I will try expressing 1112 and 695 in terms of bar length.




I will add segments in increments of n, the greatest common divisor.

It's been determined that 139 is the greatest common divisor, so far convenience, 1112 was given 8 segments and 695 was given 5 segments.In actually, it is not known how many segments are on each bar.However, we do know that both 1112 and 695 are multiples of a greatest common divisor, n.
Here ,like in the earlier operation, we will find the remainder of the larger number divided by the smaller number.




We got 417. From the diagram, we can see that 417 is a number also neatly divided into segments of width n.

I will repeat the mod operation like we did earlier.




When 695 is divided by 417, we get a remainder of 278.This remainder of 278 is also an integral multiple of n, in other words, it has the same greatest common divisor 




We repeat the division again.





Because 278 is divisible by 139, the remainder is 0.
It is here that we learn that the greatest common divisor, n is 139.



In this way, the Euclidian algorithm is able to find the greatest common divisor by simply repeating divisions.
A big advantage is that even if the 2 target numbers are huge, the algorithm is able to find the greatest common divisor with a standard procedure.



That's it guys!!!




-ThilanJR10-




















Comments

Popular posts from this blog

Ruby on Rails Tutorial

Ruby on Rails Introduction  Hi all I,m here with a new article actually It's trending laguage for you all .Invented in Japan. That means it's very active language. Also it's  need some theory parts to understand these things very well so i will go through by explaining them simply. What is Ruby? Before we Ride on Rails , let us recapitulate a few points of ruby, which is the base of Rails. Ruby is the successful combination of Smalltalk's conceptual elegance python's ease of use and learning and perl's pragmatism Ruby is   A high level programming language. Interpreted like Perl, Python , Tcl/Tk. Object oriented like Smalltalk, Eiffel, Ada ,Java Why Ruby? Ruby originated in japan and now it is gaining popularity in US and Europe  as well. The following factors contribute towards  its popularity. Easy to learn Open source(very liberal license) rich libraries very easy to extend  Truly Object Oriented Less coding with f...

Data Compression- Run Length Encoding

Hello Again!! This article is beyond from the programming. FYI as a programmer you should have a knowledge about these things. If not you will ended up with a mess. It's RLE What is it?  Run Length Encoding is a very simple form of loosless data compression in which runs of data are stored as a single data value and count, rather than as the original run. Understood? I bet you wont !! Let me go it with my way right after this article you will a have sufficient knowledge about RLE for sure. Let's Dive in ! Let's try an encoding image drawn using three colors on a 5x5 grid. First we will use simple method We have assigned a letter to each of the colors, Y for Yellow, G for Green, and B for Blue. As a result of transforming the rows into Ys,Gs nad Bs one line at a time starting from the upper left, we were able to encode the figure into a line of 25 letters. Next, using run legth encoding on the image, let's try expressing it in less than 25 le...

Quick Tutorial with Pedometer

For a better start i'm gonna go through some points Arduino uno(with connecting cable) Accelerometer Jumper Cables Bouth & Pb (since i,m a chemistry student)                                                               Ok here we go!  I hope you all familiar with what above mention with the points. If not quickly follow me whatever the social media i mentioned in my blog i'm willing to help you. First of all i would like to introduce Arduino Uno here. This is a simple picture of it. as i mention in the picture arduino uno consists with digital pins & power pins. Accelerometer is the sensor what we going to work with now.It will look like this.     in this picture it's just a sensor with holes. to fill with that up you gonna need headers(male/female). Probably now you need your bo...