0

Time complexity of the recursive call

How 'a' value is decremented throughout the recursive call.

Is it o(log a) or O(log log a) or something else

int result(int a, int b)
{
 if( a %b == 0)
    return b;
 a = a % b;
 return result(b,a);
}

  • This is called the [Euclidean Algorithm](http://mathworld.wolfram.com/EuclideanAlgorithm.html) and [this page](https://codility.com/media/train/10-Gcd.pdf) should hopefully answer your question. – ggorlen Oct 19 '19 at 15:10

1 Answers1

0

It's linear in the number of bits, i.e., O(log(n)).
Proof hint: show that after 2 iterations, a is divided by at least 2