Problem 1: The Class P (35 points)

  1. (25) Show that the class is closed under union, intersection, concatenation and complement.

Answer:

Success

Union

Let and be two languages in P. These languages are decidable and may be decided by algorithms and . We can construct a new algorithm which decides the union of and . M = “On input x:

  1. Run on input x.
  2. Run on input x.
  3. If either A1 or A2 accept x, then A accepts x.

The running time of A is the sum of the running times of A1 and A2. These algorithms would be polynomial-time. Thus, the union of and is in P.

Intersection

Similarly to union, if we have two languages and in P we may construct a new algorithm A that decides the union of and with corresponding algorithms and . M = “On input x:

  1. Run on input x.
  2. Run on input x.
  3. If either A1 or A2 accept x, then A accepts x.

Like before, the running time of A is the sum of the running times of A1 and A2. These algorithms would be polynomial-time. Thus, the intersection of and is in P.

Concatenation:

If we have and we may construct a new language . consists of all strings which can be split into two parts with part one in and part two in . We may construct an algorithm on & to determine if they are in : M = “On string input x:

  1. Run on input x to check if the first slice of the string is in .
  2. Run on input x to check if the second slice of the string is in .
  3. If the above conditions are both met, we accept x, otherwise reject x.

Because the potential number of splits is linear, we may perform these checks in polynomial-time the overall runtime is polynomial. Thus, the concatenation of and is in P

Complement

If we have language in P we may construct a new language which is the complement of . We can construct an algorithm to decide whether string x is in L2: M = “On string input x:

  1. Run on input x to check if x is NOT in L1.
  2. If x is NOT in , accept, otherwise reject.

This algorithm runs in polynomial-time and as such the complement of is in P.

  1. (10) Show that is in the class .

Answer:

Success

To demonstrate that is in , we can construct a polynomial-time algorithm to solve the decision problem.

This may be done by constructing the symmetric difference automaton C from two DFAs A and B. DFA C accepts a string only if exactly one of A or B accept it. This is done in polynomial time.

Additionally, we will construct an algorithm which decides whether a language L(C) is empty or not in polynomial time.

Consider a Turing Machine M: M = “On input C which is a DFA:

  1. Mark the start state of C.
  2. Move along the transition into the next unmarked state and mark it.
  3. Repeat step 2 until there is no remaining and reachable unmarked states.
  4. If there is a path from the start state to any accept state, we accept. Otherwise reject.

The above algorithm effectively is a graph search algorithm which runs in polynomial time.

As both algorithms run in polynomial time, their sums also run in polynomial time. This shows that is in P.

  1. (10) = { < D > | D is a DFA with L(D) = Σ* }. Show that is in the class .

Answer:

Success

We need to show that there is a polynomial time algorithm to decide if a given DFA recognizes every string over its alphabet, this is to say if .

The following is a polynomial-time algorithm which solve this decision problem:

  1. Identify all the accept states in . This can be done in linear time given the size of the DFA.

  2. Perform a graph search algorithm starting from the start state of . Mark every state that can be reached from the start state. This can also be done in linear time given the size of the DFA.

  3. Check if all states marked in step 2 are accepting states. If they are, then accepts all possible strings. If there remains any state that is reachable from the start state and is not an accept state, then .

This algorithm may be performed in polynomial time. This shows that is in .

Problem 2: The Class NP (25 points)

  1. (10) Show that the class NP is closed under union and concatenation.

Answer:

Success

If we have two languages and that are in NP, we can construct two machines and to decide and in NP time.

= On input <, , s>:

  1. Run on or on s: this must be chosen nondeterministically.
  2. If it accepts, accept. Otherwise, reject.

The Nondeterministic Turing Machine (NTM) runs in polynomial time if the NTMs for and both run in polynomial time, which is the case because and are in NP. Therefore, is also in NP.

= On input <, , s>:

  1. Choose a point to split the input string so that xy = s: the position to split must be chosen nondeterministically.
  2. Run on x.
  3. Run on y.
  4. If both instructions accept, we accept. Otherwise, we reject.

The NTM runs in polynomial time if the NTMs for and both run in polynomial time, which is the case because and are in NP. Therefore, is also in NP.

This shows the class NP is closed under union and concatenation.

  1. (15) We say that graphs and are isomorphic if the nodes of may be reordered so that it is identical to . Let are isomorphic graphs }.  Show that is in the class .

Answer:

Success

Let certificate C (sequence of nodes representing a path from to in graph ) be the reordering of G’s nodes: M = On input <G,H,C>:

  1. Check that C is a valid reordering of G’s nodes with no repetitions.
  2. Let be the reordered G.
  3. If , accept, otherwise reject.

All steps within this algorithm take either polynomial or linear time. This shows that ISO is in the class NP.

Problem 3: NP-Completeness (25 points)

A subset of the nodes of a graph is a dominating set if every other node of is adjacent to some node in . Consider the language:

has a dominating set with nodes }

Show that is NP-complete by reduction from .

Answer:

Success

We can show that DOMINATING-SET is NP-complete by creation a function to convert input for VERTEX-COVER into input for DOMINATING-SET.

M = On input <G,k>:

  1. Create graph H.
  2. For each non-zero vertex in G, add a vertex v to H.
  3. For each edge e = (u,v) in G:
  4. Add a vertex w to H.
  5. Add edges (u,v,), (u,w), and (v,w) to H.
  6. Output <H,K>

Our graph G has a vertex cover iff H has a dominating set. If has a vertex cover of size , then is also a dominating set in of size . This is because for each node that we added in , it is connected to nodes and in which are in the vertex cover (by definition of vertex cover), and hence is dominated by .

  • If has a dominating set of size , then is also a vertex cover in of size . This is because cannot contain any new nodes we added in (since these nodes are not connected to each other, they cannot dominate each other). Hence must be a subset of the original nodes from , and since is a dominating set in , it must be a vertex cover in .

This reduction can be done in polynomial time, because we can iterate through all the edges in and add new nodes in in polynomial time.

Therefore, is NP-complete.

Problem 4: NP-not-so-Completeness (30 points)

You can find the problem in our slides, and the proof of its NP-completeness in chapter 7.  Let be except with all numbers represented in unary.

  1. (15) Why is  not NP-complete when  is?

Answer:

Success

UNARY-SSUM is not NP-complete because of its input encoding. Due to the nature of unary notation, input size grows linearly with the numeric value that the unary input represents. This may throw off arithmetic calculuations. This is dissimilar to SUBSET-SUM which is in binary notation and has logarithmic representation size for a number.

  1. (15) Show that is in the class P.

Answer:

Success

We will show that is in by providing a polynomial-time algorithm that solves this decision problem.

  1. Let be the sum that we’re trying to achieve, and let the set represent our unary numbers. Initialize an array of size , where will be true if there’s a subset that adds up to and false otherwise.

  2. Set to be true, because there’s the empty subset which always sums up to 0.

  3. For each from to , and for each from decremented to , set to be true if is true. This means that if there’s a subset that sums up to , then by adding to that subset, we can also sum up to .

  4. Finally, if is true, then there’s a subset that sums up to , so we accept. Otherwise, we reject.

The runtime of this algorithm is , where is the number of unary numbers and is the sum we are trying to achieve. The size of a unary number is proportional to the value of the number and as such we may determine that the runtime is polynomial with respect to the size of the input. This shows that is in P.

Problem 5: A Contrasting Path (35 points)

A simple path in a graph is a path that contains no repeated vertices, and (therefore) no cycles. Let G be an undirected graph and consider the languages:

  1. (10) Show that SPATH is in the class P.

Answer:

Success

SPATH is in the class P since there is a polynomial time algorithm to decide if a given undirected graph has a simple path of length from to .

This may be solved as follows:

  1. Use the Breadth-First Search (BFS) algorithm from vertex in the graph . BFS visits vertices in increasing order of their distance from , this means once we reach vertex , we have found a shortest path from to .

  2. If BFS reaches the vertex and the length of the path found is , accept. If BFS has searched all vertices reachable from without finding or if the length of the path found from to is , reject.

Since BFS runs in linear-time with respect to the number of edges and vertices of the graph ( where is the the number of vertices and are the number of edges, it is a polynomial-time algorithm. This shows that is in .

  1. (25) Show that LPATH is NP-complete.

Answer:

Success

We will show that is NP-complete by demonstrating that it is in NP and that it is NP-hard.

is in NP: Given a sequence of nodes representing a path from to in graph , we can verify in polynomial time whether the path has no repeated nodes and whether it has length at least . We can do this by checking each consecutive pair of nodes in the sequence to ensure that they form an edge in and storing a set of nodes we have visited to ensure that no node appears more than once in the sequence. This shows that is in NP.

Now to prove that LPATH is NP-hard by reducing from the Hamiltonian Path problem, which is known to be NP-complete:
Given an instance of , we can construct an instance of where , , , and is the number of nodes in .

is in iff is in . A Hamiltonian path in from to is a simple path that visits every node exactly once, so its length is the number of nodes in - 1, = . As is the number of nodes in minus 1, if there is a simple path of length from to in , this path must be a Hamiltonian path from to in .

This reduction can be done in polynomial time, because we can count the number of nodes in in polynomial time.

Therefore, is NP-hard.

==This shows that is NP-complete.==

#evergreen