Euclidean algorithm: Difference between revisions

Content deleted Content added
Line 25:
Euclid's algorithm is widely used in practice, especially for small numbers, due to its simplicity. An alternative algorithm, the [[binary GCD algorithm]], exploits the [[binary numeral system|binary]] representation used by computers to avoid divisions and thereby increase efficiency, although it too is ''O''(''n''²); it merely shrinks the constant hidden by the [[big-O notation]] on many real machines.
 
== Relation with continued fractions ==
 
The quotients that appear when the Euclidean algorithm is applied to the inputs ''a'' and ''b'' are precisely the numbers occurring in the [[continued fraction]] representation of ''a''/''b''.
Take for instance the example of ''a'' = 1071 and ''b'' = 1029 used above.
Here is the calculation with highlighted quotients:
:1071 = 1029 × '''1''' + 42
:1029 = 42 × '''24''' + 21
:42 = 21 × '''2''' + 0
From this, one can read off that
:<math>\frac{1071}{1029} = \mathbf{1} + \frac{1}{\mathbf{24} + \frac{1}{\mathbf{2}}}</math>.
This method can even be used for [[real number|real]] inputs ''a'' and ''b''; if ''a''/''b'' is [[irrational number|irrational]], then the Euclidean algorithm will not terminate, but the computed sequence of quotients still represents the (now infinite) continued fraction representation of ''a''/''b''.
 
boring boring broing lol