~/ learn/ comp-372/ cards/ GCD, modular arithmetic & the Euclidean algorithm
1 of 7

Type EUCLID (the GCD recursion theorem made into an algorithm)

Type EUCLID (the GCD recursion theorem made into an algorithm)

Answer

EUCLID(a, b) if b == 0 return a return EUCLID(b, a mod b)

gcd(a,b) = gcd(b, a mod b); the second argument strictly shrinks each call, and gcd(a,0)=a is the base case. O(lg b) calls (Lamé).

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/20484ca9-b406-4073-9a22-d2f21b6b7dd4/flashcard utf-8 LF