본문 바로가기

Algorithms/Time Complexity

GCD_CMPL

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?

  •  
  •  
  •  
  •  
Good solution:

Euclidean algorithm

'Algorithms > Time Complexity' 카테고리의 다른 글

CHOOSE2  (0) 2018.10.14
REC_CMPL2  (0) 2018.10.14
CHOOSE1  (0) 2018.10.12
LOOP_CMPL2  (0) 2018.10.12
NESTED_CMPL3  (0) 2018.10.12