# Euclid's algorithm

(algorithm)

**Definition:**
An algorithm to compute the *greatest common divisor* of two positive integers. It is `Euclid(a,b){if (b=0) then return a; else return Euclid(b, a mod b);}`. The run time complexity is *O((log a)(log b))* bit operations.

**Also known as** Euclidean algorithm.

**See also**
*binary GCD*, *extended Euclid's algorithm*, *Ferguson-Forcade algorithm*.

*Note:
After [CLR90, page 810].*

Author: PEB

## Implementation

Worst-case behavior annotated for real time (WOOP/ADA).

Go to the
Dictionary of Algorithms and Data
Structures home page.

If you have suggestions, corrections, or comments, please get in touch
with Paul Black.

Entry modified 2 March 2015.

HTML page formatted Wed Mar 13 12:42:45 2019.

Cite this as:

Paul E. Black, "Euclid's algorithm", in
*Dictionary of Algorithms and Data Structures* [online], Paul E. Black, ed. 2 March 2015. (accessed TODAY)
Available from: https://www.nist.gov/dads/HTML/euclidalgo.html