The algorithm I do not understand is :
alg(m, n)
1. if m>n then
2. return alg(m-n, n)
3. else
4. if n>m then
5. return alg(n, m)
6. else
7. return n
I think that the recurrence formula is T(m) = T(m-n) + a
, where a is a constant. I tried to do a substitution:
T(m) = T(m-k) + a*n
Assume that
k=m => T(m) = T(0) + a*n => T(m) = n*a + 1 => The complexity is O(n)
.
Please tell me if I am wrong. Thank you!