I know this is a programming question but it seems to be more on the mathematical side ( recursion ) I was hoping someone would be able to explain it to me since it will probably be on my exam tomorrow.
http://vvcap.net/db/kIcAQxI5nJGOdN_l18Zb.htp
From 1,1 i cannot do it since the answer is 0 and i seem to get 0, -1 since a becomes 0 and b becomes -1....
This would be an absolute massive help if someone could explain to me where i'm going wrong because it will be worth 10 marks in the exam!
Okay, first you call
f(1,1). In this case, you have to evaluate the else branch where you havereturn f(f(a-1,b-1),b-1).Sincea=1andb=1you can replace thesea-1andb-1with its actual value0. This gives you callreturn f(f(0,0),0). Since there is no assignment of any variable, you can replace these values simultaneously. Now, you have to evaluate thisreturn f(f(0,0),0)in two steps. First you replacef(0,0)by its return value0. This gives youreturn f(0,0). Again, sincef(0,0) -> 0you havereturn 0.