word - Courses

advertisement
A few Adversary Arguments
 n
At least   adjacency questions are necessary (in worst case) to determine whether a
 2
graph G on n vertices is connected. (Recall by “adjacency” question we mean a question of the form:
“is vertex u adjacent to vertex v”.)
Theorem
Proof: Consider any algorithm for this problem, and start it on an unspecified input graph G with n
vertices. The Daemon’s strategy is to answer no to any edge probe, unless that answer would prove
that G is disconnected. More precisely, the Daemon maintains two edge sets X and Y, where initially Y
 n
is empty and X contains all   edges in K n , the complete graph on n vertices. The Daemon then
 2
performs the following algorithm when an edge e is probed:
Probe(e)
1. if X  e is connected
2.
X  X e
3.
answer No
4. else
5.
Y Y  e
6.
answer Yes
Here we abuse notation slightly and identify the edge set X with the subgraph of K n consisting of the
edges in X together with all vertices in K n (and similarly for Y.) Observe that at all times Y  X and
the set X  Y consists of precisely those edges of K n which have not yet been probed. Furthermore
both X and Y are consistent with the Daemon’s entire sequence of answers since whenever the answer
yes is given, that edge is added to Y and remains in X, while if no is given the corresponding edge is
removed from X and is not added to Y. Of course if the algorithm were to probe the same edge more
than once, the Daemon will give an answer which is consistent with his previous one. The following
invariants are maintained over any sequence of edge probes.
(a) The subgraph X is always connected. This is obvious from the construction.
(b) If X contains a cycle, then none of it’s edges belong to Y. Proof: Deleting an edge from that cycle
would leave X connected, and so that edge could not have been added to Y.
(c) It follows from (b) that Y is acyclic.
(d) If Y  X then Y is disconnected. Proof: Assume, to get a contradiction, that Y is connected. Then
being acyclic Y is a tree. Since Y  X , there exists an edge e X with eY . If e were added to
Y it would form a cycle with some of the other edges in Y. (This is a well known and obvious
property of trees: joining vertices by a new edge creates a unique cycle.) Since Y  X , that cycle
is also contained in X. In other words X contains a cycle consisting of e together with some edges
in Y. This contradicts remark (b) above. The only way to avoid this contradiction is to conclude
that Y is disconnected.
Now suppose the algorithm halts and returns a verdict (connected/disconnected) after probing fewer
 n
than   edges. Then at least one edge of K n was not probed, hence X Y   , and therefore
 2
1
Y  X . Now (d) tells us that Y is disconnected, and by (a) X is connected. Since both graphs are
consistent with the Daemon’s answers, the algorithm cannot be considered correct. If the algorithm
says G is connected, then the Daemon can claim G  Y , while if the algorithm says G is disconnected,
the Daemon may claim that G  X . Thus any correct algorithm solving this problem must probe all
 n
  potential edges.
///
 2
 n
Show that at least   'adjacency' questions are necessary to determine whether a graph G
 2
on n vertices is acyclic.
Exercise
Example Let b  b1b2b3b4b5 be a bit string of length 5, i.e. bi {0,1} for 1  i  5 . Consider the
problem of determining whether b contains three consecutive ones, i.e. whether or not b contains the
substring 111. We restrict our attention to those algorithms whose only allowable operation is to peek
at a bit. Obviously 5 peeks are sufficient. A decision tree argument provides the (useless) fact that at
least one peek is necessary.
a. Use an adversary argument to show that 4 peeks are necessary in general.
Proof: Consider any algorithm for this problem and start it on an unspecified bit b string of length
5. The Daemon’s strategy is to answer 0 to any bit peek, unless that answer would prove that b
does not contain three consecutive ones. More precisely, let x  11111 and y  00000 , and define
a function flip (u , i ) which takes a bit string u and flips it’s i th bit (0 to 1, or 1 to 0), then returns the
new bit string. When the algorithm peeks at bit i, the Daemon performs the following algorithm.
Peek(i)
1. if flip ( x, i ) contains the substring 111
x  flip ( x, i )
2.
3.
answer 0
4. else
y  flip ( y, i )
5.
6.
answer 1
Of course if the algorithm were to peek at a particular bit more than once, the Daemon will always
give an answer which is consistent with his previous one. Observe that at all times both bit strings
x and y are consistent with the Daemon’s sequence of answers, since whenever the answer 0 is
given that bit is flipped in x from 1 to 0 while that bit remains 0 in y, whereas if the answer 1 is
given the corresponding bit is flipped in y from 0 to 1 while it remains 1 in x. Also it is obvious
from Peek(i) above that x always contains the substring 111. We claim that if only 3 peeks have
been performed, then y can contain at most 2 ones. To prove this, assume that after peeking at 3
bits, y contains 3 ones. Then it must be the case that if any of those bits were flipped in x  11111,
then x would not contain the substring 111. But there are not 3 such bits in x  11111. In fact x
contains only one such bit with this property, namely x3 . This contradiction shows that if only 3
peeks are performed, then y contains at most 2 ones, and hence y cannot contain the substring 111.
Therefore if the algorithm were to halt and return a verdict after performing only 3 peeks, then it
could not possibly be correct, since if the verdict is yes, the Daemon can claim that b  y , while if
2
the verdict is no, the Daemon can cliam that b  x . Both strings are consistent with the Daemon’s
sequence of answers, and both contradict the algorithm’s verdict. In other words, no algorithm can
distinguish between x and y after just 3 peeks, whence any correct algorithm for this problem must
perform at least 4 peeks, in worst case.
///
b. Design an algorithm which solves the problem using only 4 peeks in worst case. Express your
algorithm as a decision tree.
Solution: In the decision tree below, each branch to the left indicates that the bit peek resulted in
0, while each branch to the right indicates that the peeked bit is 1.
3
No
2
4
1
No
5
No
4
Yes
No
Yes
Yes
Observe that the height of this decision tree is 4, so by part (a) above, this is an optimal algorithm.
3
Download