Complexity theory reiterates on concepts from satisfiability and NP-completeness.
NP
We define a decision problem as a problem where given an input , we output either True or False depending on if there exists a solution matching the problem’s requirements.
Suppose that we have a witness — 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 in polynomial time relative to .
Hard verifiable decision problems: There is no known polynomial time verification to the solution from ; our current understanding tells us that we need exponential time for verification.
We denote as the class of all verifiable decision problems. We could also define as the set of all search problems, where a search problem meets these conditions: (1) for an input , its algorithm outputs a solution or specifies that there is no solution, and (2) for a candidate solution , it is possible to verify its correctness in polynomial time relative to the size of .
MST Decision Problem
Given input , output whether there exists a spanning tree of with weight . 2. Verify that , where is the weight of edge .
Summing all the runtimes, we get , which is polynomial time. MST is in .
K-coloring
Given input and , output whether there exists a -coloring of . A -coloring is an assignment for all such that .
Suppose we find a candidate assignment . Then, we could iterate through each edge in and check that . This takes time, so -coloring is in .
0/1 Knapsack
Given input , a set of items with corresponding values and weights , and a capacity , output whether there exists a collection of items that maximizes the total value and keeps total weight .
Suppose we find a candidate collection . We can easily show that the total weight , 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 , but since it takes bits as the input size to represent , the runtime is , which is exponential with respect to . We hence cannot conclude that 0/1 Knapsack is in .
SAT
Given a function in conjunctive normal form (CNF), output whether there exists an assignment such that .
Suppose we have a function in CNF: and a candidate assignment . To verify , we just have to plug into . This takes time, where is the number of literals and is the number of clauses.
The subset of problems where we know of a solution that solves the problem in polynomial time is . We have that . For example, MST is in because of Kruskal’s and Prim’s.
Reductions
A reduction from problem to problem shows that is at least as hard of a problem to solve as . We take an input, or instance in problem and convert it to an input of problem using a polynomial time function . Then, we retrieve a solution by running any algorithm for , and then convert it back to a solution of using a polynomial time algorithm .
To complete the reduction, we must show that there is a solution to input for iff there is a solution to input for . We show that is just a special case of , therefore must be at least as hard as . This process involves three steps:
- Describe the function , which is the transformation of the instance for problem to instance for problem , and show that it runs in polynomial time.
- Describe the function , which converts the solution to instance from back into a solution for instance in .
- Show that there is a solution for in iff there is a solution for in . To prove that , you must show that and . It is often easier to use the contrapositive and show that and . It doesn’t need to be a rigorous formal proof, just show correspondence in both directions.
A problem is NP-hard if there exists a reduction from all problems . Therefore, is at least as hard as all problems in . Therefore, you can prove a problem is NP-hard by finding a reduction for some known NP-hard problem .
A problem is NP-complete if it is in and NP-hard. NP-complete problems are the hardest known problems in , as all other problems reduce to it.