Binary Recursive GCD algorithm analysis

440 Views Asked by At

This is a pseudocode for a Binary GCD algorithm:

Input: a, b positive integers
Output: gcd(a, b)
    if a = 0 or b = 0 return a+b
    if a = 1 or b = 1 return 1
    if a is even
        if b is even return 2*gcd(a/2,b/2)
        else return gcd(a/2,b)
    else
        if b is even: return gcd(a, b/2)
        else
           if a < b return gcd((b-a)/2, a)
           else return gcd((a-b)/2, a)

What is the running time of this algorithm?