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 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 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 is better than and is better than , then is better than .
- Antisymmetric: If is better than , then is not better than .
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
Describe an implementation of the procedure that only makes calls to . What is the expected running time of your procedure, as a function of and ?
As could be any number, we need at least bits to represent the number. We set as . Basically, we need to call times. If the number represented by binary is bigger than , 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 is . will be called times in that procedure.
The expected running time is , is . Considering is less than , so the running time is .
5.1-3
Suppose that you want to output with probability and with probability . At your disposal is a procedure , that outputs either or . It outputs with some probability and with probability , where , but you do not know what is. Give an algorithm that uses as a subroutine, and returns an unbiased answer, returning with probability and with probability . What is the expected running time of your algorithm as a function of ?
There are 4 outcomes when we call twice, i.e., , , , .
The strategy is as following:
- or : call twice again
- : output
- : output
We can calculate the probability of each outcome:
Since there's no other way to return a value, it returns and both with probability .
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 and , and subtly converts the unequal and to and , 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.
The expected number of trials for this scenario is . Thus, the expected running time of is .