222 15 Communication Complexity
bound now follows because binary trees with at least n leaves must have depth
at least log n.
It is also quite easy to design a protocol of length O(log
2
n). In this protocol
Alice and Bob perform a binary search on {1,...,n} to locate the median
M. The upper bound of O(log
2
n) will follow if we can find a protocol of
length O(log n) with which Alice and Bob can decide whether M ≤ m for any
m ∈{0,...,n}. For this, Alice sends the number of elements in S
A
and the
number of elements in {i ∈ S
A
| i ≤ m}. Now Bob can calculate the number
of elements in S
A
∪ S
B
(recall that we are considering all sets as multi-sets)
and the number of elements in {i ∈ S
A
∪ S
B
| i ≤ m}. This means he knows
the answer to the question, which he can then send to Alice.
Designing a protocol with length O(log n) is more complicated. In a
preparatory step, Alice and Bob exchange the values |S
A
| and |S
B
|.This
requires at most 2log(n +1) bits. Now let k be the smallest power of 2
for which k ≥|S
A
| and k ≥|S
B
|. Clearly k<2n. Now Alice and Bob will
add elements to the multi-sets S
A
and S
B
according to a prescribed scheme
in such a way that in the end |S
A
| = |S
B
| = k but the median of S
A
∪ S
B
remains unchanged. Each number added will be either 1 or n.Ifthenumber
of elements in |S
A
| + |S
B
| is even, then an equal number of 1’s and n’s are
used. Otherwise one more n is used than 1.
Alice and Bob know the value of k. Furthermore, they can maintain an
interval of integers that are possible values for the median. Since we want the
size of this interval I to be a power of 2, they begin with I = {1,...,2
log n
}.
We will show the claim by giving a protocol of length 2 that will halve either
k or |I|. After at most log n +logk − 1=O(log n) of these steps, either
|I| =1ork =1.If|I| = 1, then Alice and Bob know the only element in I
which is the median. If k = 1, then Alice and Bob exchange the only elements
in S
A
and S
B
; the median is the smaller of the two.
Now we must describe the promised protocol of length 2. Alice computes
the median a
of her current multi-set S
A
, and Bob computes b
from S
B
analogously. Let i be the smallest element in I. Alice considers the binary
representation of a
− i, which has length log |I|, and sends the most signif-
icant bit a
∗
to Bob. Bob does the analogous thing and sends b
∗
to Alice. If
a
∗
= b
∗
, then for the overall median M it must be that the binary represen-
tation of M − i begins with a
∗
. This suffices to halve the interval I:Ifa
∗
=0,
then I is replaced by its first half; otherwise I is replaced by its second half.
Now consider the case that a
∗
= b
∗
. For reasons of symmetry it suffices to
consider the case a
∗
= 0 and b
∗
= 1. Then Alice can remove the smaller half
of the elements from S
A
and Bob can remove the larger half of the elements
from S
B
. This cuts k in half but does not change the median. So the median
problem has communication complexity Θ(log n).
This example also shows that protocol trees are well-suited for structural
considerations, but that it is better to describe specific protocols algorithmi-
cally.