Skip to content

Advanced Topics | Computer Science

flowchart TD
A[6_Advanced Topics] --> B[Key Concepts]
A --> C[Core Principles]
A --> D[Practical Applications]
B --> E[Fundamental definitions]
C --> F[Design patterns]
D --> G[Real-world usage]

Computational complexity theory classifies problems by their inherent difficulty. P contains problems solvable in polynomial time, while NP contains those whose solutions can be verified in polynomial time. NP-complete problems are the hardest problems in NP, and if any one can be solved efficiently, all can. Polynomial-time reductions are the tool for proving NP-completeness: if problem A can be transformed into problem B efficiently, then B is at least as hard as A. The Cook-Levin theorem establishes SAT as the first NP-complete problem.

P: The class of decision problems solvable in polynomial time by a deterministic Turing machine.

NP: The class of decision problems solvable in polynomial time by a non-deterministic Turing Machine. Equivalently, problems whose “yes” instances have polynomial-time verifiable certificates.

NP-hard: A problem AA is NP-hard if every problem in NP can be reduced to AA in polynomial Time.

NP-complete: A problem is NP-complete if it is in NP and NP-hard.

Theorem 6.1. If any NP-complete problem is in P, then P = NP.

A polynomial-time reduction from problem AA to problem BB is a polynomial-time algorithm that Transforms instances of AA into instances of BBPreserving the answer.

Lemma 6.1. If ApBA \leq_p B and BPB \in P Then APA \in P.

Lemma 6.2. If ApBA \leq_p B and AA is NP-hard, then BB is NP-hard.

Theorem 6.2 (Cook-Levin, 1971). SAT is NP-complete.

Proof sketch. We show that every problem in NP reduces to SAT. Let LNPL \in \mathrm{NP}. There exists a polynomial-time non-deterministic Turing machine MM that decides LLRunning in time p(n)p(n) on inputs of length nn. For an input xxWe construct a Boolean formula ϕx\phi_x that is satisfiable if and only if MM accepts xx.

The formula encodes:

  1. Tableau variables: T[i,j,σ]=1T[i, j, \sigma] = 1 iff cell (i,j)(i, j) of the computation tableau contains symbol σ\sigma. The tableau has p(n)+1p(n) + 1 rows and p(n)p(n) columns.
  2. Initial configuration: Row 0 encodes the initial state of MM on input xx.
  3. Transition constraints: Each 2×32 \times 3 window of the tableau corresponds to a valid transition of MM.
  4. Accepting configuration: Some cell in the last row contains the accept state.

Each of these constraints can be expressed as a polynomial-size CNF formula. The total formula ϕx\phi_x has size polynomial in nn and is satisfiable iff MM accepts xx. \blacksquare

SAT. Given a Boolean formula in CNF, is there a satisfying assignment?

3-SAT. SAT restricted to clauses with exactly 3 literals.

Vertex Cover. Given a graph G=(V,E)G = (V, E) and integer kkIs there a vertex cover of size k\leq k?

Travelling Salesman Problem (decision version). Given a weighted graph and bound BBIs there a Tour of total weight B\leq B?

Subset Sum. Given a set of integers and a target TTIs there a subset summing to TT?

Clique. Given a graph GG and integer kkDoes GG contain a clique of size kk?

To prove a problem BB is NP-complete:

  1. Show BNPB \in \mathrm{NP} (polynomial-time verifiable certificate).
  2. Show a known NP-complete problem AA reduces to BB: ApBA \leq_p B.

Example. 3-SAT p\leq_p Vertex Cover: construct a graph from the 3-SAT formula where each Variable and each clause become vertices, and edges enforce the constraint that a satisfying Assignment corresponds to a vertex cover.

Worked Example: 3-SAT $\leq_p$ Vertex Cover Reduction

Reduce 3-SAT formula ϕ=(x1xˉ2x3)(xˉ1x2x3)(x1x2xˉ3)\phi = (x_1 \vee \bar{x}_2 \vee x_3) \wedge (\bar{x}_1 \vee x_2 \vee x_3) \wedge (x_1 \vee x_2 \vee \bar{x}_3) to a vertex cover instance.

For each variable xix_iCreate two vertices xix_i and xˉi\bar{x}_i connected by an edge (the “literal edge”).

For each clause CjC_jCreate a triangle of 3 vertices cj1,cj2,cj3c_{j1}, c_{j2}, c_{j3}.

For each clause vertex cjkc_{jk}Connect it to the literal vertex corresponding to the kk-th literal of clause jj.

Claim: ϕ\phi is satisfiable iff the graph has a vertex cover of size k+2mk + 2m where kk is the number of variables and mm is the number of clauses.

(\Rightarrow) If ϕ\phi is satisfiable, include in the cover: for each variable, the literal vertex matching the truth assignment (e.g., x1x_1 if x1=truex_1 = \mathrm{true}, xˉ1\bar{x}_1 if x1=falsex_1 = \mathrm{false}). This covers all literal edges (kk vertices). For each clause triangle, at least one literal in the clause is true, so the corresponding literal vertex covers one of the three edges from the triangle. Include the other two vertices of the triangle (2m2m vertices total).

(\Leftarrow) A vertex cover of size k+2mk + 2m must include exactly one endpoint of each literal edge (otherwise the triangle requires 3 vertices). Set each variable according to which literal vertex is in the cover. Each clause triangle has exactly one uncovered vertex, whose edge to a literal vertex is covered by that literal vertex, meaning the clause is satisfied.

The reduction takes polynomial time (number of vertices and edges is polynomial in the formula size).