
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