rmykkänen

notes

Complexity theory

date

Complexity theory reiterates on concepts from satisfiability and NP-completeness.

NP

We define a decision problem as a problem where given an input II, we output either True or False depending on if there exists a solution matching the problem's requirements.

Suppose that we have a witness WW — some entity that can observe the decision problem running and see a solution that the decision problem uses to output True. With this, we can divide decision problems into two classes:

Verifiable decision problems. We can verify the solution given from WW in polynomial time relative to II.

Hard verifiable decision problems: There is no known polynomial time verification to the solution from WW; our current understanding tells us that we need exponential time for verification.

We denote NP\mathsf{NP} as the class of all verifiable decision problems. We could also define NP\mathsf{NP} as the set of all search problems, where a search problem meets these conditions: (1) for an input II, its algorithm outputs a solution SS or specifies that there is no solution, and (2) for a candidate solution SS, it is possible to verify its correctness in polynomial time relative to the size of II.

MST Decision Problem

Given input I:G(V,E),rI : G(V, E), r, output whether there exists a spanning tree of GG with weight ≤r\leq r. Suppose we find a candidate set of edges SS.

  1. Verify that SS is a spanning tree: it has ∣V∣−1|V| - 1 edges, and a DFS from any vertex reaches all of VV in O(∣V∣+∣E∣)O(|V| + |E|) time.
  2. Verify that ∑e∈Sw(e)≤r\sum_{e \in S} w(e) \leq r, where w(e)w(e) is the weight of edge ee.

Summing all the runtimes, we get O(∣V∣+∣E∣)O(|V| + |E|), which is polynomial time. MST is in NP\mathsf{NP}.

K-coloring

Given input I:G(V,E)I: G(V, E) and k∈Nk \in \mathbb{N}, output whether there exists a kk-coloring of GG. A kk-coloring is an assignment σ\sigma for all v∈Vv \in V such that ∀e=(u,v)∈E,σ(u)≠σ(v)\forall e = (u,v) \in E, \sigma(u) \neq \sigma(v).

Suppose we find a candidate assignment SS. Then, we could iterate through each edge (u,v)(u, v) in GG and check that σ(u)≠σ(v)\sigma(u) \neq \sigma(v). This takes O(∣E∣)O(|E|) time, so kk-coloring is in NP\mathsf{NP}.

0/1 Knapsack

Given input II, a set of items 1..n{1 .. n} with corresponding values v1..vnv_1..v_n and weights w1..wnw_1 .. w_n, and a capacity BB, output whether there exists a collection of items that maximizes the total value and keeps total weight ≤B\leq B.

Suppose we find a candidate collection SS. We can easily show that the total weight ≤B\leq B, but we will need to run Knapsack-search to find if the total value is maximized. However, Knapsack-search runs in pseudo-polynomial time, which is really exponential time. The runtime of Knapsack-search is O(nB)O(nB), but since it takes log2(B)log_2(B) bits as the input size to represent BB, the runtime is O(n2log2B)O(n2^{log_2B}), which is exponential with respect to II. We hence cannot conclude that 0/1 Knapsack is in NP\mathsf{NP}.

SAT

Given a function f:x1..xn→0,1f: {x_1 .. x_n} \rightarrow {0, 1} in conjunctive normal form (CNF), output whether there exists an assignment x1..xn{x_1 .. x_n} such that f=1f = 1.

Suppose we have a function ff in CNF: (x1∨x2∨x3∨x4)∧(xˉ1∨xˉ4∨x5∨x6)∧(x3∨xˉ5∨x7)(x1 ∨ x2 ∨ x3 ∨ x4) ∧ (\bar{x}1 ∨ \bar{x}4 ∨ x5 ∨ x6) ∧ (x3 ∨ \bar{x}5 ∨ x7) and a candidate assignment S:x1..x7S: {x1 .. x7}. To verify SS, we just have to plug SS into ff. This takes O(nm)O(nm) time, where nn is the number of literals and mm is the number of clauses.

The subset of NP\mathsf{NP} problems where we know of a solution that solves the problem in polynomial time is P\mathsf{P}. We have that P⊆NP\mathsf{P} \subseteq \mathsf{NP}. For example, MST is in P\mathsf{P} because of Kruskal's and Prim's.

Reductions

A reduction from problem AA to problem BB shows that BB is at least as hard of a problem to solve as AA. We take an input, or instance II in problem AA and convert it to an input I′I' of problem BB using a polynomial time function ff. Then, we retrieve a solution S′S' by running any algorithm for BB, and then convert it back to a solution SS of AA using a polynomial time algorithm hh.

Reducing problems in complexity theory

To complete the reduction, we must show that there is a solution to input II for AA iff there is a solution to input I′I' for BB. We show that AA is just a special case of BB, therefore BB must be at least as hard as AA. This process involves three steps:

  1. Describe the function ff, which is the transformation of the instance II for problem AA to instance f(I)=I′f(I) = I' for problem BB, and show that it runs in polynomial time.
  2. Describe the function hh, which converts the solution to instance I′I' from BB back into a solution for instance II in AA.
  3. Show that there is a solution for II in AA iff there is a solution for I′I' in BB. To prove that a↔ba \leftrightarrow b, you must show that a→ba \rightarrow b and b→ab \rightarrow a. It is often easier to use the contrapositive and show that a→ba \rightarrow b and ¬a→¬b\neg a \rightarrow \neg b. It doesn't need to be a rigorous formal proof, just show correspondence in both directions.

A problem CC is NP-hard if there exists a reduction A≤pCA \leq_p C from all problems A∈NPA \in \mathsf{NP}. Therefore, CC is at least as hard as all problems in NP\mathsf{NP}. Therefore, you can prove a problem DD is NP-hard by finding a reduction H≤pDH \leq_p D for some known NP-hard problem HH.

A problem CC is NP-complete if it is in NP\mathsf{NP} and NP-hard. NP-complete problems are the hardest known problems in NP\mathsf{NP}, as all other NP\mathsf{NP} problems reduce to it.