Consider the following game. A dealer produces a sequence s1 sn of cards, face up | StudySoup

Textbook Solutions for Algorithms

Chapter 6 Problem 6.13

Question

Consider the following game. A dealer produces a sequence s1 sn of cards, face up, whereeach card si has a value vi. Then two players take turns picking a card from the sequence, butcan only pick the first or the last card of the (remaining) sequence. The goal is to collect cards oflargest total value. (For example, you can think of the cards as bills of different denominations.)Assume n is even.(a) Show a sequence of cards such that it is not optimal for the first player to start by pickingup the available card of larger value. That is, the natural greedy strategy is suboptimal.(b) Give an O(n2) algorithm to compute an optimal strategy for the first player. Given theinitial sequence, your algorithm should precompute in O(n2) time some information, andthen the first player should be able to make each move optimally in O(1) time by lookingup the precomputed information.

Solution

Step 1 of 3

(a) Let's consider a sequence (3,5,1,2).

The available card at first is 3 then the second player grabs the next card 5 and will win.

If the first player picks the last card or rightmost card from the set, then the first player will get a chance to pick the card 5 and will win.

Hence, a greedy approach does not guarantee the optimal result to the first player.

Subscribe to view the
full solution

Title Algorithms  1 
Author Sanjoy Dasgupta Algorithms, Christos H. Papadimitriou Algorithms, Umesh Vazirani Algorithms
ISBN 9780073523408

Consider the following game. A dealer produces a sequence s1 sn of cards, face up

Chapter 6 textbook questions

×

Login

Organize all study tools for free

Or continue with
×

Register

Sign up for access to all content on our site!

Or continue with

Or login if you already have an account

×

Reset password

If you have an active account we’ll send you an e-mail for password recovery

Or login if you have your password back