Seyed Masoud Hosseini · Overview · Study log · Weekly summaries · Ideas · Search · Transcript · RSS feed
Design & Analysis of Algorithms · Lecture 23 of 34 · 45:46
Recitation 8: NP-Complete Problems
Study guide
What this lecture covers
This MIT 6.046 recitation practices the mechanics of NP-hardness reductions after the main lecture introduced P, NP, and NP-completeness. It answers a practical question: given a problem you already know is NP-hard, how do you construct a polynomial-time transformation that proves a new problem is NP-hard too, and how do you rigorously argue that the transformation preserves the yes/no answer in both directions?
The recitation works three examples of increasing difficulty. After watching, you should be able to reduce Hamiltonian cycle to Hamiltonian path, clique to independent set, and clique to Max-2-SAT, and you should understand why every such proof needs both an NP-membership argument and a two-directional correctness argument for the reduction.
Key ideas
- Reduction recipe: to prove problem B is NP-hard, take a known NP-hard problem A, give a polynomial-time transformation from any A-input to a B-input, and show the two instances have the same yes/no answer.
- Contrapositive logic: if B had a polynomial-time algorithm, composing the reduction with it would solve A in polynomial time; since A is assumed hard, B cannot be easy either.
- Certificates for NP membership: for each new problem, a short check-able solution (a path, an independent set, a variable assignment) shows the problem is in NP before showing it's hard.
- Vertex splitting: splitting a vertex into an "in" copy and an "out" copy converts a Hamiltonian cycle problem into a Hamiltonian path problem by breaking the cycle at one point.
- Complement graph: swapping edges and non-edges converts a clique in the original graph into an independent set in the complemented graph.
- Max-2-SAT: given clauses of at most two literals, decide whether some assignment satisfies at least
Kof them; reducing clique to it requires building clauses that reward exactly the vertices in a target clique. - Two-directional correctness: a full reduction proof must show both that a solution to the source problem yields a solution to the target problem, and that a solution to the target problem can be converted back into a solution to the source problem.
Walkthrough
Recap and the reduction framework (0:00)
The recitation reviews P as problems with a polynomial-time decision algorithm and NP as problems whose answers are verifiable in polynomial time given a certificate. It then lays out the reduction template used for the rest of the session: to show problem B is NP-hard using known-hard problem A, build a polynomial-time function that transforms any input of A into an input of B with the same answer, so that an efficient algorithm for B would imply an efficient algorithm for A.
Hamiltonian cycle to Hamiltonian path (4:04)
Starting from the known-hard Hamiltonian cycle problem (a cycle visiting every vertex exactly once), the recitation reduces it to Hamiltonian path (a path, not necessarily closed, visiting every vertex). The transformation splits one chosen vertex into two copies, one keeping all incoming edges and one keeping all outgoing edges. The proof shows both directions: a Hamiltonian cycle through the original vertex becomes a Hamiltonian path once the vertex is split, and any Hamiltonian path in the split graph must start at the incoming-only copy and end at the outgoing-only copy, so merging them back recreates a cycle.
Clique to independent set (13:28)
The second reduction starts from the k-clique problem (does the graph contain a fully-connected subset of k vertices?) and targets independent set (does the graph contain a subset of k vertices with no edges between them?). The transformation simply complements the graph's edge set: every edge becomes a non-edge and vice versa. A clique in the original graph is then exactly an independent set in the complemented graph, since every pair connected before is disconnected after, and this argument is shown to hold in both directions.
Setting up clique to Max-2-SAT (21:47)
The final, more involved reduction targets Max-2-SAT: given 2-literal clauses, decide whether an assignment satisfies at least K of them. Given a graph and target clique size K, the construction creates one literal per vertex plus a dummy variable Z. It adds a clause (not x_i OR not x_j) for every non-edge (i,j), plus clauses (x_i OR Z) and (x_i OR not Z) for every vertex, and sets the satisfaction threshold to |complement edges| + |V| + K. The intuition is that setting exactly the clique's vertices to true (and everything else false) satisfies all the non-edge clauses, all the Z clauses, and exactly K of the not Z clauses.
Proving the Max-2-SAT reduction correct (28:53)
The recitation verifies the forward direction algebraically: assigning true to a size-K clique's vertices and false elsewhere satisfies every non-edge clause, every x_i OR Z clause, and exactly K of the x_i OR not Z clauses, matching the threshold. The reverse direction is harder: starting from an assignment that satisfies at least the threshold number of clauses, the recitation defines a candidate vertex set from the variables set to true, then shows that whenever this set contains a "violating" pair with no edge between them (so it isn't yet a clique), flipping that variable to false loses at most one satisfied clause but gains at least one back, leaving the total unchanged. Repeating this process removes all violations without lowering the satisfied-clause count, eventually producing an actual clique whose size, by the same counting argument, must be at least K.
Before you watch
- Review the definitions of P, NP, NP-hard, and NP-complete from the main lecture on complexity.
- Know the Hamiltonian cycle and clique problems as commonly cited NP-hard problems.
- Be comfortable reading Boolean clause notation such as
(x_i OR not x_j).
Check your understanding
- Why does a reduction from A to B need to run in polynomial time for the NP-hardness argument to work?
- In the Hamiltonian path reduction, why must any Hamiltonian path in the split graph start at the incoming-only vertex copy?
- Why does complementing a graph's edges turn a clique into an independent set?
- In the Max-2-SAT reduction, why are the
(x_i OR Z)and(x_i OR not Z)clauses needed in addition to the non-edge clauses? - In the reverse direction of the Max-2-SAT proof, why does flipping a violating vertex's variable to false never decrease the total number of satisfied clauses?
Vocabulary
- reduction recipe (noun)
- A standard method for proving a new problem is hard by transforming a known hard problem into it.
The reduction recipe requires a polynomial-time transformation. - contrapositive (noun)
- A logical restatement where the reverse and negation of a statement is used instead.
The contrapositive argument shows an easy algorithm for B would make A easy too. - Hamiltonian cycle (noun)
- A loop through a graph that visits every vertex exactly once and returns to the start.
Finding a Hamiltonian cycle is a well-known hard problem. - Hamiltonian path (noun)
- A route through a graph visiting every vertex exactly once, without needing to return to the start.
A Hamiltonian path doesn't have to close into a loop. - clique (noun)
- A group of vertices in a graph that are all directly connected to each other.
Finding the largest clique in a graph is NP-hard. - independent set (noun)
- A group of vertices in a graph with no edges connecting any of them.
An independent set has no two vertices directly connected. - complement graph (noun)
- A graph formed by swapping every edge and non-edge from the original graph.
A clique becomes an independent set in the complement graph. - vertex splitting (noun)
- Dividing one node into two separate copies to change a graph's structure.
Vertex splitting breaks a cycle into a path. - threshold (noun)
- A minimum value that must be reached for a condition to count as satisfied.
Max-2-SAT asks whether a threshold number of clauses can be satisfied. - NP-hard (adjective)
- Describing a problem at least as hard as the hardest problems in NP.
Proving a new problem is NP-hard uses a reduction from a known one. - certificate (noun)
- A short piece of evidence that lets a proposed solution be checked quickly.
A path is a certificate that a graph has a Hamiltonian cycle. - transformation (noun)
- A change from one form or structure into another.
The reduction defines a transformation from one graph problem to another. - literal (noun)
- A single variable or its negation used inside a logical clause.
Each clause in Max-2-SAT contains at most two literals. - clause (noun)
- A small logical statement combining literals with OR.
The construction adds one clause for every non-edge in the graph. - satisfy (logic) (verb)
- To make a logical statement true under a given assignment.
The chosen assignment must satisfy at least K clauses. - dummy variable (noun)
- An extra variable added only to help a construction work, without real meaning of its own.
The reduction introduces a dummy variable Z for bookkeeping. - algebraically (adverb)
- Using symbols and equations rather than pictures or intuition.
The forward direction is verified algebraically. - violation (noun)
- A case where a rule or condition is broken.
The proof removes each violation one at a time. - polynomial-time (adjective)
- Describing an algorithm whose running time grows no faster than a fixed power of input size.
The reduction must run in polynomial-time to be valid. - membership (set) (noun)
- Belonging to a particular group or category.
The proof first shows NP membership before showing hardness. - compose (verb)
- To combine two processes so one feeds into the other.
Composing the reduction with a fast algorithm for B would solve A quickly. - mechanics (of a method) (noun)
- The specific steps and details of how something works.
The recitation practices the mechanics of NP-hardness reductions. - assignment (variable) (noun)
- A specific true or false value given to each variable.
The proof looks at an assignment that satisfies enough clauses. - candidate (set) (noun)
- A possible option being considered before it's confirmed correct.
The proof builds a candidate vertex set from the true variables. - rigorously (adverb)
- In a very careful, precise, and logically complete way.
The recitation argues rigorously that the reduction preserves the answer.
Chapters
- 0:00 <Untitled Chapter 1>
- 1:47 Np-Hard Problems
- 4:33 Hamiltonian Path
- 4:40 Hamiltonian Cycle
- 5:57 Link Path
- 7:05 Reduction
- 15:17 Independent Set
- 16:31 Transformation
- 23:10 Decision Problem
- 44:31 Np-Hard Reductions
From the YouTube description
MIT 6.046J Design and Analysis of Algorithms, Spring 2015
View the complete course: http://ocw.mit.edu/6-046JS15
Instructor: Amartya Shankha Biswas
In this recitation, problems related to NP-Completeness are discussed.
License: Creative Commons BY-NC-SA
More information at http://ocw.mit.edu/terms
More courses at http://ocw.mit.edu
← Lecture 16: Complexity - P, NP, NP-completeness, Reductions · Lecture 17: Complexity - Approximation Algorithms →
