~/ 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/a747440d-151d-4705-b647-8adea780f9b3/flashcard utf-8 LF