140k views
5 votes
Two players take turns removing a ball from a jar that initially contains m white and n black balls. The first player to remove a white ball wins. Develop a recursive algorithm for determining the winner.

a) Recursive algorithm is not suitable for this problem
b) Use a brute force approach
c) Develop a dynamic programming solution
d) Analytical solution is not possible

1 Answer

3 votes

Final answer:

The recursive algorithm is suitable for this problem. Here's a recursive algorithm to determine the winner:

Step-by-step explanation:

The recursive algorithm is suitable for this problem. Here's a recursive algorithm to determine the winner:

  1. If the jar contains only white balls, the first player wins.
  2. If the jar contains only black balls, the second player wins.
  3. If the jar contains both white and black balls, the first player removes a ball from the jar:
  4. If it's a white ball, the first player wins.
  5. If it's a black ball, the second player removes a ball from the jar:
  6. If it's a white ball, the second player wins.
  7. If it's a black ball, the game continues recursively.

This algorithm assumes that both players make optimal decisions at each turn.

User Ecarrizo
by
7.3k points