1

In the following C++ function, let n >= m.

    int gcd(int n, int m) {
            if (n%m ==0) return m;
            if (n < m) swap(n, m);
            while (m > 0) {
                n = n%m;
                swap(n, m);
            }
            return n;
    }

What is the time complexity of the above function assuming n > m?

Raymond Chen
  • 44,448
  • 11
  • 96
  • 135
  • 6
    Does this answer your question? [Time complexity of Euclid's Algorithm](https://stackoverflow.com/questions/3980416/time-complexity-of-euclids-algorithm) – Mark Plotnick Feb 12 '20 at 18:02

0 Answers0