The function terminates when a==b; so to show that it doesn't terminate, you could show that a & b never get closer together with successive calls -- which in this case, is pretty easy.
(The above does not take into account overflow. Also, (d) can't be correct, since it doesn't loop at all.)
manpreet
Best Answer
3 years ago
I have this exam question:
Look at this example of pseudocode:
algorithm A(a, b) { // precond: a & b are type of Int // postcond: what does this function return? if (a == b) return( 0 ) else if (a < b) return (-A(b, a)) else return (A(a-1, b-1)); }The answers given are:
Personally I think it's d), but I just wanted to make sure.