* Problems in P * The class NP * Introduction to NP-completeness PROBLEMS IN P The vast majority of the problems that you must have studied in an advanced algorithms course are in P. Many of those problems are formulated as optimization problems. There is a distinction, but you can formulate decision versions of the problems and consider their complexity following the models we have developed. SHORTEST_PATH = { : G is a directed graph with integer weights on edges such that the shortest path from s to t is of length <= k} NETWORK_FLOW = { : G is a directed graph with integer capacities on edges such that the maximum flow from s to t is of value >= k} STRONGLY_CONNECTED = { : G is a directed graph in which there is a path between any pair of vertices} THE CLASS NP Two definitions: one a natural generalization of P, and the other in terms of verifiers. NTIME(t(n)) = {L : L is a language decided by an O(t(n)) time nondeterministic Turing machine} NP = U_k NTIME(n^k) A verifier for a language L is an algorithm V, where L = {w: V accepts for some string c}. The verifier is a special TM whose time is expressed only in terms of the length of w. NP = Class of languages that have polynomial time verifiers. Theorem: Both of the above definitions are equivalent. Proof: Consider a language L. Let V be a poly time verifier for L. The NDTM for deciding L simply selects a candidate certificate c of length n^k, and calls V on . Accept if V accepts, reject otherwise. Let L be decided by NDTM N. Then for any w, there exists a branch of length <= n^k that accepts w. The verifier V simply interprets a certificate as a branch of N and simulates it. Accepts if N accepts on that branch, rejects otherwise. End Proof Theorem: P is subset of NP Trivial Proof. What other problems are there? A clique is a complete subgraph. CLIQUE = {: G is an undirected unweighted graph and has a clique of size k} A vertex cover is a set of vertices such that every edge is adjacent to at least one vertex in the cover. VERTEX_COVER = {: G has a vertex cover of size k} Given a bipartite graph, does there exist a 2-D matching? 3D_MATCHING We have already shown that a t(n)-time NDTM can be simulated by a 2^{O(t(n))}-time DTM. So we have: NP is a subset of U_k TIME(2^{n^k}) = EXPTIME NP-COMPLETENESS A is poly-time many-one reducible to B if there exists a poly-time computable function f such that w is in A iff f(w) is in B. Theorem: If A <=P B and B is in P, then A is in P. A language B is NP-complete if it satisfies two conditions: