Computer Science Canada

Euclidean Algorithm (greatest common divisor)

Author:  randint [ Wed Aug 01, 2012 8:57 pm ]
Post subject:  Euclidean Algorithm (greatest common divisor)

Just some fun stuff......the Euclidean Algorithm for finding the greatest common divisor of 2 natural numbers, a and b

Author:  Panphobia [ Sun Nov 18, 2012 3:07 pm ]
Post subject:  Re: Euclidean Algorithm (greatest common divisor)

cant it be done simpler like this?
code:
public static int gcd(int m, int n) {
        if ((m % n) == 0) {
            return n;
        } else {
            return gcd(n, m % n);
        }
    }

Author:  Panphobia [ Sun Nov 18, 2012 3:08 pm ]
Post subject:  RE:Euclidean Algorithm (greatest common divisor)

Sorry didnt read euclidean algorithm, my bad Very Happy

Author:  randint [ Sun Nov 18, 2012 5:18 pm ]
Post subject:  RE:Euclidean Algorithm (greatest common divisor)

Again, not that it is impossible, but recursion somehow sucks...computational complexity


: