Define the optimization problem LONGEST-PATH-LENGTH as the relation that associates each instance of an undirected graph and two vertices with the number of edges in a longest simple path between the two vertices. Define the decision problem LONGEST-PATH
$=\{\langle G, u, v, k \rangle : G = (V, E)$ is an undirected graph,$u, v \in V$ ,$k \ge 0$ is an integer, and there exists a simple path from$u$ to$v$ in$G$ consisting of at least$k$ edges$\}$. Show that the optimization problem LONGEST-PATH-LENGTH can be solved in polynomial time if and only if LONGEST-PATH$\in$ P.
- LONGEST-PATH-LENGTH can be solved in polynomial time
$\Rightarrow$ LONGEST-PATH$\in$ P
Suppose it takes
- LONGEST-PATH-LENGTH can be solved in polynomial time
$\Leftarrow$ LONGEST-PATH$\in$ P
Suppose LONGEST-PATH can be solved in
Give a formal definition for the problem of finding the longest simple cycle in an undirected graph. Give a related decision problem. Give the language corresponding to the decision problem.
- Formal definition
Instance: a graph
Solutions: a seqeunce of vertices in the graph
Problem: find the simple cycle in
- Decision problem
If
- Language
Give a formal encoding of directed graphs as binary strings using an adjacency-matrix representation. Do the same using an adjacency-list representation. Argue that the two representations are polynomially related.
- Adjacency-matrix
Suppose the matrix is
- Adjacency-list
The head of the encoding is
- Polynomially related
matrix -> list: get column number list -> matrix: fill 1s
Is the dynamic-programming algorithm for the 0-1 knapsack problem that is asked for in Exercise 16.2-2 a polynomial-time algorithm? Explain your answer.
No. The algorithm runs in
Show that if an algorithm makes at most a constant number of calls to polynomial-time subroutines and performs an additional amount of work that also takes polynomial time, then it runs in polynomial time. Also show that a polynomial number of calls to polynomial-time subrountines may result in an exponential-time algorithm.
- Constant number
- Polynomial number
Suppose the size of the output of a subrountines is twice the size of the input, then the algorithm is at least
Show that the class P, viewed as a set of languages, is closed under union, intersection, concatenation, complement, and Kleene star. That is, if
$L_1, L_2 \in \text{P}$ , then$L_1 \cup L_2 \in \text{P}$ ,$L_1 \cap L_2 \in \text{P}$ ,$L_1L_2 \in \text{P}$ ,$\overline{L_1} \in \text{P}$ , and$L_1^* \in \text{P}$ .
Suppose
$L_1 \cup L_2 \in \text{P}$
IF A_1(x) == 1 || A_2(x) == 1
THEN RETURN 1
ELSE RETURN 0
$L_1 \cap L_2 \in \text{P}$
IF A_1(x) == 1 && A_2(x) == 1
THEN RETURN 1
ELSE RETURN 0
$L_1L_2 \in \text{P}$
FOR i = 1 .. n
IF A_1(x_1 ... x_i) == 1 && A_2(x_i+1 ... x_n) == 1
THEN RETURN 1
RETURN 0
$\overline{L_1} \in \text{P}$
IF A_1(x) == 1:
RETURN 0
RETURN 1
$L_1^* \in \text{P}$
IF x == epsilon
THEN RETURN 1
FOR i = 1 .. n
DP[i] = 0
DP[0] = 1
FOR i = 0 .. n
FOR j = i + 1 .. n
IF A_1(x_i ... x_j) == 1
THEN DP[j] = 1
RETURN DP[n]