Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the following card game between two players. The dealer deals n cards face up in a row. Each card has a value visible to

Consider the following card game between two players. The dealer deals n cards face up in a row. Each card has a value visible to both players. The players move in sequence. Each player, at her turn, can pick either the rightmost or the leftmost of the remaining cards on the table. The game ends when no cards are left. The goal of each player is to accumulate as much value as possible. For example, suppose that n = 5 and the cards have values 3, 2, 1, 7, 4 in order from left to right. Then suppose the players pick the cards in the order 4, 7, 3, 2, 1, where boldface indicates the first players picks, and the remainder the second players picks. Then the first player gets total value 4 + 3 + 1 = 8 and the second gets value 7+2 = 9. On the other hand, if the players pick the cards in the order 3, 4, 7, 2, 1, then the first player gets total value 3+ 7+ 1 = 11 and the second gets value 4+ 2 = 6. One can check that the first player can guarantee no better than 8 when picking 4 as the first card. So, the first player should start by picking the leftmost card with value 3. Design and analyze O(n 2 ) time algorithm for computing the optimal strategy for the first player. In particular, given a list of values, your algorithm should output whether the first player should pick the leftmost or the rightmost card in order to maximize her total value. Assume that the second player also plays optimally. We recommend using dynamic programming for this problem. Your submission should contain the following parts. (1) Clearly define a recursive function and provide the recursive equations for the function. (2) Give a brief informal argument justifying your recursive equation. We do not need a formal proof. (3) Provide an algorithm based on the recursive equation. (4) Argue the running time of your algorithm.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine Ricardo

2nd Edition

1449606008, 978-1449606008

More Books

Students also viewed these Databases questions

Question

How would you typify the trends of trade unionism internationally?

Answered: 1 week ago