1 a) Let p be the probability that x is found in one location in the upper half.
Then
pn/2 + 9pn/2 = 1 holds (we are assuming here that x is in the array).
Hence p = 1/5n.
b) For simplicity let us ignore floor/ceiling.
First to get a general idea. If x is at n/2, then 1 comparison is necessary.
If x is at n/4(lower half) or 3n/4 (upper half), then 2 comparisons are necessary.
If x is at n/8 or 3n/8 (lower half), or 5n/8 or 7n/8 (upper half),
then 3 comparisons are necessary......
Since x is at each location in the lower half with probability 9p, and in the upper half
with p, the average time T(n) in this case is:
c)
Since
,
.
2 a) A decision problem (or a language) is in class NP if and only if it has a certificate
of length polynomial in the size of the problem, and there is a polynomial time algorithm
that verifies the certificate.
More rigorously, a language L is in class NP if and only if there is a certificate y
and
an algorithm A such that for any string x of L, y for x is of length bounded by
for some constant c, and A produces 1 given x and y for xin time polynomial in
,
where
is the length of x.
b) A subset T of S is a certificate. Since T is a subset of S, the length of
the certificate is certainly a polynomial in the size of the problem, which is
.
A verification algorithm must check:
1) T is a subset of S,
2) T is a set(included in 1)), that is there are no duplications in T, and
3)
,
in polynomial time.
1) and 2) each take O(n2) time, and 3) takes O(n) time, where n is the number of
elements in S.
Hence the partition problem is in class NP.
3 a) A polynomial reduction is a mapping of one problem say P to another say Q,
producing
an instance of Q for each instance of P such that
b) Let a set S of objects {
a1, ..., an} and their size s(a1), ..., s(an)be the given instance of the partition problem.
We construct the corresponding instance of the bin packing problem as follows:
Let U = S, and
s(ui) = 2s(ai)/V for each
,
and let the number of bins k = 2,
where
.
Clearly these can be obtained in time polynomial in the size of the partition problem.
Let us now see whether or not the answer to an instance p of the partition problem is always
the same as that to the corresponding instance q of the bin packing problem.
Suppose that the answer to p is 'yes'. Then we have a set
,
such that
.
Hence
.
Hence we can pack into one bin the objects ui's corresponding to the ai's in T,
and pack the rest into another bin.
If the answer to p is 'yes' on the other hand, then there is no such set T. Hence no matter how we group the objects of U into two groups, one of them can not be packed into a bin.
Thus the answer to p is always the same as that for q.