I'm trying to come up with the recurrence relation for Stein's Algorithm (binary GCD algorithm), but my ability to trace through it is proving not up-to-scratch.
I'm completely stumped by the multiple paths and recursive calls, as well as the fact that we're dealing with the total bits to represent our values rather than the values themselves.
Here's the algorithm:
stein(u, v):
if either of u or v are 0: return their sum.
if either of u or v are 1: return 1.
if both u and v are even: return 2 * stein(u/2, v/2)
if u is even and v is odd: return stein(u/2, v)
if u is odd and v is even: return stein(u, v/2)
if both u and v are odd: return stein(larger-smaller/2, smaller)
I'm trying to find the recurrence relation T(n) where n is the total number of bits needed to represent both u and v. I think the first step here for me should be working out when worst-case performance occurs.
I think that each division operation reduces the number of bits by 1, but that's about the most I understand thus far.
I've tried tracing the algorithm but to no avail. I've also read the relevant section of Knuth Vol. 2 but I think it's a little outside the current scope of my understanding because it made little sense to me.