34.1-1:
Assumption: the graph is unweighted
LONGEST-PATH-LENGTH ∈P=> LONGEST-PATH∈P:
Suppose there's a problem solves LHS in polynomial time, gives result k; then for the problem of RHS, it returns true if the given k' <= k.
LONGEST-PATH∈P:=> LONGEST-PATH-LENGTH ∈P:
Guess the k to the point where the LHS just returns false. Then we knows that the solution to the RHS is that k - 1.
34.1-2:
Formal Definition:
For a given undirected unweight graph G = <V,E> where V is the set of vertexes and E is the set of edges, find the number of vertexes which the longest simple cycle passes within the graph.
Related Decision Problem:
For a given input x = <V,E,k>, algorithm A returns true if there's a cycle with length at least k
Language corresponding to the decision problem:
L = {<V,E,k>: V is the set of vertex, E is the set of edges, and k >= 0 is an integer; and there exists a simple cycle in G = <V,E> consisting of at least k edges}
34.1-3:
Note: define 6-consecutive-0s as the separator. The "000000" would never occur in the formal def. The | used below is the "000000" sequence. If "00000" appears as non-separator, then it would be replaced by "000001"
Example Graph:
V = {1,2,3}; E = {1->2, 1->3, 2->1, 3->1}
Adj-Matrix:
|
1 |
2 |
3 |
1 |
0 |
1 |
1 |
2 |
1 |
0 |
0 |
3 |
1 |
0 |
0 |
Adjacency-Matrix:
[v = # of vertexes] | [v * v Adj-matrix]
From the above example: 11 000000 011 100 100
Explanation: 11 is v = # of vertex = 3; then the separator; then the 3*3 array. The space is just added for better understanding; in the real case there's no space
Adjacency-List:
[v = # of vertexes] |
(use ceil(log(v)) bits to represent one number, output the adj-matrix)
[ [e = # of edges] [adj list] ]
From the above example: 11 000000 10 1011 01 01 01 01
Explanation: 11 is v = # of vertex = 3; then separator; then 10 = 2 is the number of edges that the first node is connecting to; then following the 2 index of node (1011) that the first element is connecting to. Same logic follows for the rest.
Proof that the two encoding are polynomially related: using transfer algorithm it's easy to show that one from can be transformed to another form in polynomial time. Formally define as below:
E1 = encoding of the <V,E> to adj-matrix as above
E2 = encoding of the <V,E> to adj-list as above
f12 = transforming function trans E1 form into E2 form
f21 = transforming function trans E2 form into E1 form
f12 and f21 have been done in the chapter on Graph, that they're O(v^2). Therefore, the encodings are polynomially related.
34.1-4: No it's not. The time complexity of that 0-1 knapsack is O(nW); however, W is binary encoded from the input. Say m = log(W), i.e. the size of input is W (ignore the n part cuz it doesn't affect here), then the time complexity is actually 2^n. Thus it's not polynomial time algorithm.
34.1-5: Define polynomial algorithm A,B, such that T(A) = O(n^c), where c is constant.
If by solving B we need to call A a constant d number of times, then T(A) = O((n^c)^d) = O(n^cd). (cuz the output of A can be used as the input as another A, therefore the input size to A may grow polynomially)
If otherwise, by solving b we need to call A polynomial X number of times, then T(A) = O((n^c)^x) = O(n^(cX)). Note that if X has an n term, then the result in exponential-time.
34.1-6: Er… for this one some advanced mathematical analysis is involved which I've never learnt before.. don't know how to write it properly yet.. but believe me it's true ;)