Practice Problems on Algorithms Design - Assignment 8 | CS 1510, Assignments of Computer Science

Material Type: Assignment; Class: ALGORITHM DESIGN; Subject: Computer Science; University: University of Pittsburgh; Term: Fall 2006;

Typology: Assignments

Pre 2010

Uploaded on 09/02/2009

koofers-user-wyk
koofers-user-wyk 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS1510 Design and Analysis of Algorithms, Fall 2006
Homework 8. Assigned on Thu Nov 2nd, 2006. Due in class on Wed Nov 8th, 2006.
1. Consider the simplified mastermind game. In this game there is a hidden sequence H = (c1,
c2, …, ck) of k colored pegs. There are C possible different colors. Colors can be repeated in
the hidden sequence. The game consists of 0 or more guessing rounds and ends in an output
round. In a guessing round, the guesser gives the hider a sequence G = (g1, g2, …, gk) of
colors of length k. The hider then tells the guesser how many of the positions are correct,
that is, the number of indices j such that hj = gj. This ends a guessing round. In an output
round, the guesser produces a sequence G = (g1, g2, …, gk) of colors of length k as its output.
Note that the hider does not give any response to the guesser in the output round.
The guesser is said to identify a sequence H if, given that the hidden sequence is H, the
guesser produces H as its output. An algorithm is said to solve the game if for any sequence
H, the algorithm identifies H. In other words, an algorithm is said to solve the game if for
any H, when the hidden sequence is H, the algorithm produces H as its output.
Give an algorithm that solves the game when k=2 and C=4. You should describe your
algorithm as a decision tree. Guessing rounds should be represented as internal nodes and
output rounds should be represented as leaf nodes.
2. In this problem you will analyze your algorithm in problem 1.
(a) What hidden sequence(s) that your algorithm can identify that needs the minimum
number of guessing rounds?
(b) How many guessing rounds does your algorithm need to identify a hidden sequence in
part (a)?
(c) What hidden sequence(s) that your algorithm can identify that needs the maximum
number of guessing rounds?
(d) How many guessing rounds does your algorithm need to identify a hidden sequence in
part (c)?
(e) Suppose you want to brag to someone that you have devised an algorithm that can
intelligently play the simplified mastermind game. Suppose you want to say “No matter
what the hidden sequence is, my algorithm can find it in at most X guessing rounds.”
What is the value of X for your algorithm?
(f) Define the worst-case performance of an algorithm for this game to be the maximum
number of guessing rounds needed to identify any hidden sequence. What is the worst-
case performance of your algorithm? Does this relate to the value of X in part (e)?
3. Consider following class of related algorithms. Let Q be any sequence of length k of C
colors. Algorithm ALGQ works as follow. In the first guessing round, it guesses Q. If the
hider responds with k, the algorithm enters the output round and produces Q as its output.
Otherwise, the algorithm makes a number of guessing rounds. In particular, it enumerates all
possible sequences of length k with C colors, and uses each of the sequences in a guessing
round. It records all the responses from the hider. After that it picks a sequence S whose
response from the hider is k, enters the output round, and produces S as its output.
(a) Does the existence of this class of algorithms mean that the lower bound on the worst-
case performance of any algorithm for this game is 1?
1
pf2

Partial preview of the text

Download Practice Problems on Algorithms Design - Assignment 8 | CS 1510 and more Assignments Computer Science in PDF only on Docsity!

CS1510 Design and Analysis of Algorithms, Fall 2006 Homework 8. Assigned on Thu Nov 2nd, 2006. Due in class on Wed Nov 8th, 2006.

  1. Consider the simplified mastermind game. In this game there is a hidden sequence H = ( c 1 , c 2 , …, ck ) of k colored pegs. There are C possible different colors. Colors can be repeated in the hidden sequence. The game consists of 0 or more guessing rounds and ends in an output round. In a guessing round, the guesser gives the hider a sequence G = ( g 1 , g 2 , …, gk ) of colors of length k. The hider then tells the guesser how many of the positions are correct, that is, the number of indices j such that hj = gj. This ends a guessing round. In an output round, the guesser produces a sequence G = ( g 1 , g 2 , …, gk ) of colors of length k as its output. Note that the hider does not give any response to the guesser in the output round. The guesser is said to identify a sequence H if, given that the hidden sequence is H, the guesser produces H as its output. An algorithm is said to solve the game if for any sequence H, the algorithm identifies H. In other words, an algorithm is said to solve the game if for any H, when the hidden sequence is H, the algorithm produces H as its output. Give an algorithm that solves the game when k=2 and C=4. You should describe your algorithm as a decision tree. Guessing rounds should be represented as internal nodes and output rounds should be represented as leaf nodes.
  2. In this problem you will analyze your algorithm in problem 1. (a) What hidden sequence(s) that your algorithm can identify that needs the minimum number of guessing rounds? (b) How many guessing rounds does your algorithm need to identify a hidden sequence in part (a)? (c) What hidden sequence(s) that your algorithm can identify that needs the maximum number of guessing rounds? (d) How many guessing rounds does your algorithm need to identify a hidden sequence in part (c)? (e) Suppose you want to brag to someone that you have devised an algorithm that can intelligently play the simplified mastermind game. Suppose you want to say “No matter what the hidden sequence is, my algorithm can find it in at most X guessing rounds.” What is the value of X for your algorithm? (f) Define the worst-case performance of an algorithm for this game to be the maximum number of guessing rounds needed to identify any hidden sequence. What is the worst- case performance of your algorithm? Does this relate to the value of X in part (e)?
  3. Consider following class of related algorithms. Let Q be any sequence of length k of C colors. Algorithm ALGQ works as follow. In the first guessing round, it guesses Q. If the hider responds with k, the algorithm enters the output round and produces Q as its output. Otherwise, the algorithm makes a number of guessing rounds. In particular, it enumerates all possible sequences of length k with C colors, and uses each of the sequences in a guessing round. It records all the responses from the hider. After that it picks a sequence S whose response from the hider is k , enters the output round, and produces S as its output. (a) Does the existence of this class of algorithms mean that the lower bound on the worst- case performance of any algorithm for this game is 1? 1

(b) What is the worst-case performance of each algorithm in this class?

  1. In this problem you will determine a lower bound on the worst-case performance of any algorithm for the simplified mastermind game. We say that a problem has a lower bound of Z if there is no algorithm that solves the problem with a worst-case performance smaller than Z. (a) Consider the algorithms in problem 3. For each hidden sequence H, there exists an algorithm that identifies H using only 1 guessing round. Does this mean that the lower bound on the worst-case performance of any algorithm for this game is 1? Why or Why not? (b) How many possible output values are there for an algorithm that solves the game? (c) In a guessing round, how many possible responses from the hider are there? (d) Using the decision tree method, what is the lower bound on the worst-case performance of any algorithm for this game? 2