For this purpose, consider an arbitrary algorithm A that merges sequences u1, u2, ...., un and v1, v2, ...., vn such that
repeat ui and vj = the next pair of keys to be compared; if i=j then answer "ui precedes vj" else if i<j then answer "ui precedes vj" else answer "vj precedes ui" end end endAnother way of describing this algorithm is saying
(u1 and v1), (v1 and u2), (u2 and v2), ... , (vn-1 and un), (un and vn)of keys that are adjacent in the input template remains uncompared, and so the answers provided by the oracle match not only this template, but also the template where the order of these two keys is switched.
For example, let us take n=5. If u2 and v2 remain uncompared, then the answers provided by the oracle match both templates
u1 < v1 < u2 < v2 < u3 < v3 < u4 < v4 < u5 < v5and
u1 < v1 < v2 < u2 < u3 < v3 < u4 < v4 < u5 < v5.If v3 and u4 remain uncompared, then the answers provided by the oracle match both templates
u1 < v1 < u2 < v2 < u3 < v3 < u4 < v4 < u5 < v5and
u1 < v1 < u2 < v2 < u3 < u4 < v3 < v4 < u5 < v5.And so on.
For this purpose, consider an arbitrary algorithm A that
finds the largest of keys u1, u2, ...., un
and accesses the input only through the comparison oracle.
Let us simulate the oracle by the following algorithm:
For this purpose, consider an arbitrary algorithm A that finds
the median of a set S of 2k+1 keys and accesses the input only through
the comparison oracle. Let us simulate the oracle by the following
algorithm:
We propose to show that
For this purpose, consider an arbitrary algorithm A that finds
the counterfeit in a set P of n coins and accesses the input only
through the use of pharmacy scales. Let us simulate the outcomes of
the weighings by the following algorithm:
For this purpose, consider an arbitrary algorithm A that
sorts a set S of n keys and accesses the input only through
the comparison oracle. Let us simulate the oracle by the following
algorithm:
If A is an algorithm that attempts to determine g(x) of an
unknown input x by calling the oracle as few times as possible, then
an adversary strategy against A simulates the oracle
in a way that attempts to keep g(x) unknown as long as possible.
The non-adaptive adversary strategies are particularly simple:
they have the form
The adaptive adversary strategies used in Examples 4 and 5 generalize
as follows:
Example 2: Finding the maximum
We propose to show that
for i = 1 to n do candidate(ui)=YES end
repeat ui and uj = the next pair of keys to be compared;
if i<j
then answer "ui precedes uj"
candidate(ui)=NO;
else answer "uj precedes ui"
candidate(uj)=NO;
end
end
Another way of describing this oracle is saying
If A calls the oracle fewer than n-1 times, then at least
two of the n keys uk have candidate(uk)=YES;
one of these is un and the other has k<n.
But then the answers provided by the oracle match not only the
initial template, but also the template
(and remove a key from the list of candidates for the maximum
as soon as it has been pronounced smaller than another key).
u1 <
u2 <
... <
uk-1 <
uk+1 <
... <
un <
uk.
Non-adaptive and adaptive oracle simulations
The two oracle simulations used in Examples 1 and 2 have a
common feature: they start out with an input template,
u1 < v1 < u2 < v2 <
... <
un < vn in Example 1
and
u1 < u2 < ... <
un in Example 2,
and answer all questions as if the unknown input matched this template.
Such oracle simulations might be called non-adaptive. More
sophisticated oracle simulations construct the template
incrementally in a way that depends on A's questions. One
example of such an adaptive oracle simulation is coming up
next.
Jump to:
Example 3: Finding the median
We propose to show that
takes at least 3k calls of the comparison oracle in the worst case.
/* Initialization */
for all elements u of S
do rank(u) = "unassigned";
candidate(u) = YES;
end
/* Adaptive stage */
num_small = 0, num_large = 0;
while num_small < k and num_large < k
do u,v = the next pair of keys to be compared;
if rank(u) = "unassigned"
then if rank(v) = "unassigned"
then num_small = num_small+1, rank(u) = num_small;
num_large = num_large+1, rank(v) = k+1+num_large;
else if rank(v) < k+1
then num_large = num_large+1, rank(u) = k+1+num_large;
else num_small = num_small+1, rank(u) = num_small;
end
end
else if rank(v) = "unassigned"
then if rank(u) < k+1
then num_large = num_large+1, rank(v) = k+1+num_large;
else num_small = num_small+1, rank(v) = num_small;
end
end
end
if rank(u) < rank(v)
then answer "u precedes v"
if k+1 < rank(u) then candidate(v) = NO end
if rank(v) < k+1 then candidate(u) = NO end
else answer "v precedes u"
if k+1 < rank(v) then candidate(u) = NO end
if rank(u) < k+1 then candidate(v) = NO end
end
end
/* Completing the template */
w = an element of S such that rank(w) = "unassigned";
rank(w) = k+1;
if num_small = k
then for all elements u of S
do if rank(u) = "unassigned"
then num_large = num_large+1, rank(u) = k+1+num_large;
end
end
else for all elements u of S
do if rank(u) = "unassigned"
then num_small = num_small+1, rank(u) = num_small;
end
end
end
/* Non-adaptive stage */
repeat u,v = the next pair of keys to be compared;
if rank(u) < rank(v)
then answer "u precedes v";
if rank(u) is at least k+1 then candidate(v) = NO end
if rank(v) is at most k+1 then candidate(u) = NO end
else answer "v precedes u";
if rank(v) is at least k+1 then candidate(u) = NO end
if rank(u) is at most k+1 then candidate(v) = NO end
end
end
Let us say that a call of oracle is useful if it brings about
setting candidate(w)=NO
for some w
. In the
adaptive stage, at least k calls of the oracle are countered by
setting the value of rank(u) or rank(v) or both in such a way that
the smaller of rank(u), rank(v) is smaller than k+1 and
none of these calls are useful. It follows that, as long as A
calls the oracle fewer than 3k times, at most 2k-1 of these calls are
useful, and so in the end at least two distinct elements
the larger of rank(u), rank(v) is larger than k+1;
w
of S have candidate(w)=YES
. In
particular, there is an element x
of S such that
rank(x)
is not k+1
and such that
candidate(x)=YES
. If rank(x) < k+1, then set
newrank(x) = k+1,
newrank(y) = rank(y)-1 whenever rank(x) < rank(y) < k+2,
newrank(y) = rank(y) for all other choices of y;
if rank(x) > k+1,
then set
newrank(x) = k+1,
newrank(y) = rank(y)+1 whenever k < rank(y) < rank(x),
newrank(y) = rank(y) for all other choices of y;
The answers that oracle has provided are consistent with the linear
order defined by rank(.) as well as with the linear order defined by
newrank(.). However, the median with respect to rank(.) differs from
x, which is the median with respect to newrank(.).
Jump to:
Example 4: Finding a counterfeit coin
We have a number of coins which look alike; one of them is counterfeit
and all of the remaining ones are genuine; all the genuine coins have
an equal weight and the counterfeit coin is lighter. To find the
counterfeit coin, we may use pharmacy scales as many times as
necessary. In each weighing, we put an equal number of coins in each
tray of the scales: the counterfeit is in the lighter set of coins or,
in case the two sets are equally heavy, in the set of coins that has
been left out.
repeat L,R = the two sets of coins to be placed on the two trays;
/* we have |L|=|R| */
if |L| > |P|/3
then answer "L is lighter than R";
P = L;
else answer "L and R are of equal weight";
remove both L and R from P;
end
/* the counterfeit is in P */
end
After t iterations, the size of P is at least
n / 3t . In particular, if t <
lg n / lg 3, then the size of P is greater than 1, and so the
answers that the oracle has provided are consistent with at least two
distinct choices of the counterfeit.
Jump to:
Example 5: Sorting
We propose to show that
P = the set of all linear orders on S;
repeat u,v = the next pair of keys to be compared;
P(u) = the set of all linear orders in P where u precedes v;
P(v) = the set of all linear orders in P where v precedes u;
if |P(u|) > |P(v)|
then answer "u precedes v";
P = P(u);
else answer "v precedes u";
P = P(v);
end
end
After t iterations, the size of P is at least
n! / 2t . In particular, if t <
lg(n!), then the size of P is greater than 1, and so the
answers that the oracle has provided are consistent with at least two
distinct linear orders on S.
Jump to:
A unified general setting and information-theoretic bounds
In general, the oracle is specified by a set Q of
questions and each question is a function f defined on P.
Each access of an input x by the oracle amounts to choosing a question
f in Q and asking the oracle for the answer f(x).
In general, let g denote the function that associates an output g(x) with
each input x.
choose an element y of P;
repeat f = the next function in Q for which
the oracle is asked to return f(x);
answer "f(y)";
end
repeat f = the next function in Q for which
the oracle is asked to return f(x);
w = an element of f(P) that
maximizes |{g(x) : x is in P and f(x)=w}|;
answer "w";
P = {x : x is in P and f(x)=w};
end
To analyze this algorithm, let us write
Jump to:
Back to the table of contents of Vaek Chvátal's
course notes