Why it matters

Euclidean algorithm is foundation. Understanding shapes number theory.

Advertisement

The architecture

gcd(a, 0) = a.

Else gcd(a, b) = gcd(b, a mod b).

Terminates fast (Fibonacci worst case).

Euclidean algorithmgcd(a, b)iterationReduce b, a mod brecursiveTerminate at 0return aO(log min(a, b)) iterations; Lame's theorem gives Fibonacci worst-case
Euclidean.
Advertisement

How it works end to end

Recursion or iteration.

Fibonacci worst case.

Binary GCD variant faster on binary hardware.