Question: Consider the following recursive algorithm Beer(n), which takes as input an integer n greaterthanorequalto 1: Algorithm BEER(n) if n = 1 then eat some peanuts

 Consider the following recursive algorithm Beer(n), which takes as input an

Consider the following recursive algorithm Beer(n), which takes as input an integer n greaterthanorequalto 1: Algorithm BEER(n) if n = 1 then eat some peanuts else drink one pint of beer choose an arbitrary integer m with 1 lessthanorequalto m lessthanorequalto n - 1 BEER(m) Beer(h - m) (a) Draw a possible recursion tree for Beer(6). (b) Explain why, for any integer n > 1, algorithm beer(n) terminates. (c) Let B(n) be the number of pints of beer you drink when running algorithm Beer(ti). Give the recurrence relation for B(n). (d) Use your recursion tree to guess what the exact value of B(n) is. Then use induction to prove that your guess is correct

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!