CS 600 Solutions to Test I
October 14, 1998



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:
$T(n) = \Theta(9p(1*1 + 2*1 + 3*2 + 4*4 ...) + p(2*1 + 3*2 + 4*4 + ...))$



c) $T(n) = \Theta(10p \Sigma_{i=2}^{\lg n} i 2^{i-2} + 9p)$
$= \Theta(5p/2\Sigma_{i=1}^{\lg n} i 2^{i} + 4p)$
$= \Theta(1/n((\lg n -1)2^{\lg n} + 2)4/5n)$



Since $2^{\lg n} = n$, $T(n) = \Theta(\lg n)$.



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 $O(\sim x \sim^{c})$ for some constant c, and A produces 1 given x and y for xin time polynomial in $\sim x \sim$, where $\sim x \sim$ 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 $O(\sim S \sim)$.

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) $\Sigma_{a_{i} \in T} s(a_{i}) = \Sigma_{a_{i} \in S - T} s(a_{i})$,
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

(1)
the mapping takes polynomial time and
(2)
the answer to an instance of P is the same as that for the corresponding instance of Q.



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 $u_{i} \in U$, and let the number of bins k = 2, where $V = \Sigma_{a_{i} \in S} s(a_{i})$.
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 $T \subseteq S$, such that $\Sigma_{a_{i} \in T} s(a_{i}) = \Sigma_{a_{i} \in S - T} s(a_{i})$.
Hence $\Sigma_{a_{i} \in T} s(a_{i})/V = \Sigma_{a_{i} \in S - T} s(a_{i})/V = 1$.
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.



 

S. Toida
1999-08-30