Skip to content

5.1 The hiring problem

5.1-1

Show that the assumption that we are always able to determine which candidate is best in line 4 of procedure HIRE-ASSISTANT\text{HIRE-ASSISTANT} implies that we know a total order on the ranks of the candidates.

A total order is a partial order that is a total relation (a,bA:aRb or bRa)(\forall a, b \in A:aRb \text{ or } bRa). A relation is a partial order if it is reflexive, antisymmetric and transitive.

Assume that the relation is good or better.

  • Reflexive: This is a bit trivial, but everybody is as good or better as themselves.
  • Transitive: If AA is better than BB and BB is better than CC, then AA is better than CC.
  • Antisymmetric: If AA is better than BB, then BB is not better than AA.

So far we have a partial order.

Since we assume we can compare any two candidates, then comparison must be a total relation and thus we have a total order.

5.1-2 \star

Describe an implementation of the procedure RANDOM(a,b)\text{RANDOM}(a, b) that only makes calls to RANDOM(0,1)\text{RANDOM}(0, 1). What is the expected running time of your procedure, as a function of aa and bb?

As (ba)(b - a) could be any number, we need at least lg(ba)\lceil \lg(b - a) \rceil bits to represent the number. We set lg(ba)\lceil \lg(b - a) \rceil as kk. Basically, we need to call RANDOM(0,1)\text{RANDOM}(0, 1) kk times. If the number represented by binary is bigger than bab - a, it's not valid number and we give it another try, otherwise we return that number.

RANDOM(a, b)
    range = b - a
    bits = ceil(log(2, range))
    result = 0
    for i = 0 to bits - 1
        r = RANDOM(0, 1)
        result = result + r << i
    if result > range
        return RANDOM(a, b)
    else return a + result

The expectation of times of calling procedure RANDOM(a,b)\text{RANDOM}(a, b) is 2kba\frac{2^k}{b - a}. RANDOM(0,1)\text{RANDOM}(0, 1) will be called kk times in that procedure.

The expected running time is Θ(2kbak)\Theta(\frac{2^k}{b - a} \cdot k), kk is lg(ba)\lceil \lg(b - a) \rceil. Considering 2k2^k is less than 2(ba)2 \cdot (b - a), so the running time is O(k)O(k).

5.1-3 \star

Suppose that you want to output 00 with probability 1/21 / 2 and 11 with probability 1/21 / 2. At your disposal is a procedure BIASED-RANDOM\text{BIASED-RANDOM}, that outputs either 00 or 11. It outputs 11 with some probability pp and 00 with probability 1p1 - p, where 0<p<10 < p < 1, but you do not know what pp is. Give an algorithm that uses BIASED-RANDOM\text{BIASED-RANDOM} as a subroutine, and returns an unbiased answer, returning 00 with probability 1/21 / 2 and 11 with probability 1/21 / 2. What is the expected running time of your algorithm as a function of pp?

There are 4 outcomes when we call BIASED-RANDOM\text{BIASED-RANDOM} twice, i.e., 0000, 0101, 1010, 1111.

The strategy is as following:

  • 0000 or 1111: call BIASED-RANDOM\text{BIASED-RANDOM} twice again
  • 0101: output 00
  • 1010: output 11

We can calculate the probability of each outcome:

  • Pr{0011}=p2+(1p)2\Pr\{00 | 11\} = p^2 + (1 - p)^2
  • Pr{01}=(1p)p\Pr\{01\} = (1 - p)p
  • Pr{10}=p(1p)\Pr\{10\} = p(1 - p)

Since there's no other way to return a value, it returns 00 and 11 both with probability 1/21 / 2.

The pseudo code is as follow:

UNBIASED-RANDOM
    while true
        x = BIASED-RANDOM
        y = BIASED-RANDOM
        if x != y
            return x

This algorithm actually uses the equivalence of the probability of occurrence of 0101 and 1010, and subtly converts the unequal 0000 and 1111 to 0101 and 1010, thus eliminating the probability that its probability is not equivalent.

Each iteration is a Bernoulli trial, where "success" means that the iteration does return a value.

We can view each iteration as a Bernoulli trial, where "success" means that the iteration returns a value.

Pr{success}=Pr{0 is returned}+Pr{1 is returned}=2p(1p). \begin{aligned} \Pr\{\text{success}\} & = \Pr\{0\text{ is returned}\} + \Pr\{1\text{ is returned}\} \\ & = 2p(1 - p). \end{aligned}

The expected number of trials for this scenario is 1/(2p(1p))1 / (2p(1 - p)). Thus, the expected running time of UNBIASED-RANDOM\text{UNBIASED-RANDOM} is Θ(1/(2p(1p))\Theta(1 / (2p(1 - p)).