I study my middle age, and one of the practice questions asks:
Consider the recursive pseudo-algorithm Milk (a), which takes a> = 1 as an input integer.
MILK(a)
if a = 1;
then eat cookie;
else drink glass of milk;
select a random integer b with 1 <= b <= a-1
MILK(b);
MILK(a-b);
endif
1) Explain why for any integer a> = 1, the MILK (a) algorithm completes
I think that for this, because of n-1, the possibility for m becomes less and less for input into the recursive function MILK (b); ultimately reaches 1, which satisfies the condition a = 1; therefore there is a cookie and thus completes the algorithm.
2) Let M (a) be the number of glasses of milk you drink while working MILK (a). Determine the exact value of M (a)
For this, I assume that it will be M (a) = a + a, since every time you run it 'a', entering and adding each input together will give you the total.
? . !