From the course: Python: Recursion
Unlock the full course today
Join today to access over 24,200 courses taught by industry experts.
Recursive greatest common divisor function in Python - Python Tutorial
From the course: Python: Recursion
Recursive greatest common divisor function in Python
- [Instructor] The greatest common divisor algorithm dates back to Euclid in ancient Greece. And is fundamental to modern cryptography and therefore to the internet itself. Take a look at this slide. The basic idea is that the GCD, that's the greatest common divisor, of two separate numbers must necessarily be the same as the GCD of their difference, i.e. what you get when you subtract one from the other. This idea is then extended to division since division can be thought of as repeated subtraction. So we consider the remainder after dividing one number by another. That might sound quite abstract, so let's look at a concrete example. Suppose you wish to find the GCD, that's the greatest common divisor, of 32 and 12. What you can see here is we have the end of the process that the answer is in fact four. And you can see the four is going into 32 and 12 an even number of times with no remainders. So how does it work?…