Exam pseudocode recursive function -
Exam pseudocode recursive function -
i have exam question:
look @ illustration of pseudocode:
algorithm a(a, b) { // precond: & b type of int // postcond: function return? if (a == b) return( 0 ) else if (a < b) homecoming (-a(b, a)) else homecoming (a(a-1, b-1)); } the answers given are:
a) a-b b) a+b c) max(a,b) d) loop infinitelypersonally think it's d), wanted create sure.
the function terminates when a==b; show doesn't terminate, show & b never closer successive calls -- in case, pretty easy.
(the above not take business relationship overflow. also, (d) can't correct, since doesn't loop @ all.)
pseudocode
Comments
Post a Comment