Solutions to CS 600 Test I


October 9, 2002


1. Find the big-oh relationships for the following functions. Give your calculations. [20]

$3^{n}$, $n2^{n}$, $n^{1/2} \ln n$, $n^{3/4}$, $n !$.

Solutions

Guess the order as

$\sqrt{n} \ln n \prec n^{3/4} \prec n 2^{n} \prec 3^{n} \prec n !$,
where $\prec$ means "is little oh of".

Let us now try to check the guess.
(a) $\sqrt{n} \ln n \prec n^{3/4}$
$lim_{n \rightarrow \infty}$ $ n^{3/4} / \sqrt{n} \ln n$ = $lim_{n \rightarrow \infty}$ $ n^{1/4} / \ln n$
= $lim_{n \rightarrow \infty}$ $ (1/4) n^{-3/4} / (1/n)$ = $lim_{n \rightarrow \infty}$ $ (1/4) n^{1/4} $ = $\infty$
Hence $\sqrt{n} \ln n \prec n^{3/4}$.

(b) $n^{3/4} \prec n 2^{n} $
$lim_{n \rightarrow \infty}$ $n^{3/4} / n 2^{n} $ = $lim_{n \rightarrow \infty}$ $1/n^{1/4} 2^{n} $ = $0$.
Hence $n^{3/4} \prec n 2^{n} $.

(c) $n 2^{n} \prec 3^{n}$
$lim_{n \rightarrow \infty}$ $ n 2^{n} / 3^{n} $ = $lim_{n \rightarrow \infty}$ $ n / (3/2)^{n} $
= $lim_{n \rightarrow \infty}$ $ 1 / (3/2)^{n} \ln (3/2)$ $=$ $0$
Hence $n 2^{n} \prec 3^{n}$.

(d) $3^{n} \prec n ! $
$lim_{n \rightarrow \infty}$ $3^{n} / n ! $ = $lim_{n \rightarrow \infty}$ $3*3*3...*3 / n(n-1)(n-2)...1$
= $lim_{n \rightarrow \infty}$ $(3/1)*(3/2)*(3/3)*(3/4)*...(3/n-1)*(3/n)$ = $\leq lim_{n \rightarrow \infty}$ $3*(3/2)*(3/4)^{n-3}$ = $0$.
Hence $3^{n} \prec n ! $.

2. Let $L$ be an array of size $4n$, let $L[i]$ denote the $i$-th key of $L$, let $x$ be the key being searched for in $L$, and let $p(i)$ be the probability for $x = L[i]$.
Suppose that $x$ is always found in $L$ with the following probability:

$p(i) = ci$ for $1 \leq i \leq n/4$
$= 3n/4 - ci/3 $ for $n/4 \leq i \leq n$


where $c$ is a constant.

(a) Formulate the equation for computing the average time of the Sequential Search with the probability distribution given above in terms of $c$ and $n$. Do not compute. [6]
(b) Compute the average time from (a). You do not have to compute the value of $c$ yet. [7]
(c) Determine the value of constant $c$ in terms of $n$ and express the average time in terms of $n$ only. What is the asymptotic average time ? [7]

You may use the following formulas if you need them:

$\Sigma_{i=1}^{n} i2^{i} = (n - 1) 2^{n + 1} + 2$, $\Sigma_{i=1}^{n} i^{2} = n( n + 1 )(2n + 1)/6$,
$\Sigma_{i=1}^{n} i^{3} = ( n( n + 1 )/2 )^{2}$, $\lg (n!) = \Theta(n\lg n)$.

Solutions

(a) $\Sigma_{i=1}^{n} ip(i) = \Sigma_{i=1}^{n/4}ici + \Sigma_{i=n/4+1}^{n}(nc/3 - ci/3)i$


(b) $\Sigma_{i=1}^{n/4}ici + \Sigma_{i=n/4+1}^{n}(nc/3 - ci/3)i$
= $c \Sigma_{i=1}^{n/4} i^{2} + nc/3\Sigma_{i=n/4+1}^{n} i - c/3 \Sigma_{i=n/4+1}^{n} i^{2}$
= $c \Sigma_{i=1}^{n/4} i^{2} + nc/3\Sigma_{i=n/4+1}^{n} i + c/3 \Sigma_{i=1}^{n/4} i^{2}
- c/3 \Sigma_{i=1}^{n} i^{2}$
= $ 5cn^{3} / 96 $.

(c) Since $\Sigma_{i=1}^{n} p(i)$ = $1$, $\Sigma_{i=1}^{n/4}ci + \Sigma_{i=n/4+1}^{n}(nc/3 - ci/3)$ = $1$
Computing the left hand side, we get $cn^{2}/8$ which is equal to $1$.
Hence $c = 8 / n^{2}$.
Substituting this $c$ into the equation of (b), we get $5n/12$ for the average time which is $\Theta ( n )$.

3. Answer whether or not the following statements are true. You DO NOT need to give your reasons. [20]

(a) An NP-complete problem can be solved in $O(a^{p(n)})$ time for some constant $a$ in the worst case, where $n$ is the problem size and $p(n)$ is a polynomial in $n$.
(b) If a problem is in class $NP$, then it can be solved by back tracking a polynomial number of times in the worst case.
(c) If $f(n) = O(g(n))$, then $f(n) = o(g(n))$.
(d) If a problem is in class NP, then it can not be solved in polynomial time in the worst case.
(e) Some problems in class NP need $2^{2^{n}}$ time to solve in the worst case.

Solutions

(a) True.
All the others are false.

4. A vertex cover of a graph is a subset of its vertex set such that every edge of the graph is incident to at least one of the vertices in the subset.
The vertex cover problem asks whether or not a vertex cover of size $k$ exists for a given graph.

Prove that the vertex cover problem is NP-complete. [20]
You may assume the followings:
(a) The vertex cover problem is in class NP.
(b) Graph Color, Bin Packing, Clique, 3SAT and Partition are NP-complete.

Solution: See the textbook.

5. The problem given below is called "Job Scheduling with Penalties". Prove that it is in class NP. [20]

There are $n$ jobs $J_{1}, ... , J_{n}$ to be executed one at a time. We are given execution times $t_{1}, ..., t_{n}$, deadline dates $d_{1}, ..., d_{n}$ and penalties for missing the deadlines $p_{1}, ..., p_{n}$. Assume that these numbers are all positive integers. The problem is to find a schedule (i.e. sequence) of jobs so that the total penalty is less than or equal to a given positive integer $k$.

Solution:

For a certificate we can use a sequence of jobs. It is certainly of length polynomial in the size of the problem.

The following algorithm is a verification algorithm.
It is assumed that the jobs are renumbered so that the first job is $J_{1}$, the second is $J_{2}$ etc.

$T = 0$; $P = 0$;
for ( $i = 1 ; i \leq n ; i++$) {
    $T := T + t_{i}$;
    if $T > d_{i} $ then $P := P + p_{i}$
}
if $ P > k$, then return "no"
else return "yes".

Since the for loop takes at most $n$ iterations, this verification algorithm is of polynomial time ($O(n)$). If you want to check whether or not all $n$ jobs are accounted for, it can easily be done by modifying this algorithm. It would still be $O(n)$.
Hence the Job Scheduling with Penalties problem is in class NP.