University of Auckland · FACULTY OF COMPUTER SCIENCE

COMPSCI320 Chap.13 NP-Completeness and Polynomial-Time Reductions

- one subject, every graph, every model, every mark
6 Chapters5-page Bible
Our own words - no uploaded lecturer files
Updated for this semester
Chapter 13 of 13 · COMPSCI320

NP-Completeness and Polynomial-Time Reductions

The last module asks what to do when no efficient algorithm is likely.

This chapter defines polynomial-time reductions and their direction, separates P, NP, NP-hard and NP-complete with certificates and certifiers, proves clique NP-complete from independent set, builds the 3-SAT to independent set gadget, and surveys the colouring, subset-sum and knapsack reductions from the lecture.

The worked proof gives a certificate, a certifier and a reduction with both directions, the structure the NP activity asks for.

A figure draws the clause triangles for a three-clause formula, and the practice cards apply the vertex cover to set cover reduction and test reasoning about the direction of reductions.

In this chapter

What this chapter covers

  • 01

    Polynomial-time reductions and their direction

  • 02

    Certificates and certifiers

  • 03

    P, NP, NP-hard and NP-complete

  • 04

    Independent set, vertex cover and clique

  • 05

    The 3-SAT to independent set gadget

  • 06

    Colouring, subset sum and knapsack reductions

Worked example · free

Build the clause triangles for three clauses

Q [4 marks]. For the three clauses (x1 ∨ ¬x2 ∨ x3), (¬x1 ∨ x2 ∨ x3) and (x1 ∨ x2 ∨ ¬x3), build the graph with one triangle per clause, one vertex per literal and an edge from each literal to its negation, then use a satisfying assignment to find an independent set of size 3. The marks are an AskSia practice weighting, not a university marking scheme.
The graph built from three clauses (x1 ∨ ¬x2 ∨ x3), (¬x1 ∨ x2 ∨ x3) and (x1 ∨ x2 ∨ ¬x3).The graph built from three clauses (x1 ∨ ¬x2 ∨ x3), (¬x1 ∨ x2 ∨ x3) and (x1 ∨ x2 ∨ ¬x3). Blue triangles hold each clause's literals and the 6 dashed red edges join every literal to its negation in another clause.x1¬x2x3¬x1x2x3x1x2¬x3
The graph built from three clauses (x1 ∨ ¬x2 ∨ x3), (¬x1 ∨ x2 ∨ x3) and (x1 ∨ x2 ∨ ¬x3). Blue triangles hold each clause's literals and the 6 dashed red edges join every literal to its negation in another clause.
  • 1Make a triangle of three literal vertices for each clause.
  • 1Join every literal to each occurrence of its negation in another clause, and set k = 3.
  • 1The assignment x1, x2 and x3 all true satisfies every clause.
  • 1Choose x1, x2 and x1 from the three triangles; no edge joins them, so the set has size 3.
This four-mark allocation is an AskSia practice weighting and not an official university scheme. The construction has nine vertices, and the satisfying assignment gives an independent set of size 3, one vertex per triangle.
Sia tip — Write X ≤p Y at the top and check that your construction starts from an instance of the known hard problem X.
Glossary

Key terms

Polynomial-Time Reduction
A method of solving one problem with polynomially many steps and calls to a solver for another problem.
Certifier
A polynomial-time algorithm that checks a proposed certificate for a yes answer.
NP-Complete Problem
A problem that belongs to NP and to which every problem in NP reduces in polynomial time.
Vertex Cover
A set of vertices that touches every edge of a graph.
Reduction Gadget
A small constructed piece of an instance that forces one variable, clause or choice to behave as required.
3-SAT
The satisfiability problem for formulas whose clauses each contain exactly three literals.
FAQ

NP-Completeness and Polynomial-Time Reductions FAQ

Which way should a hardness reduction go?

From the known hard problem to the new one. To show a new problem Y is hard, take an arbitrary instance of a known NP-complete problem X and build an instance of Y with the same answer, proving X ≤p Y. Reducing Y to X only shows Y is no harder than X, which says nothing about its difficulty.

Why must a reduction be proved in both directions?

The constructed instance must have exactly the same answer as the original. Showing only that yes for X gives yes for Y would allow a construction that always outputs a yes instance, which proves nothing. The second direction, that a yes for Y yields a yes for X, is what makes the answers equivalent.

Does an O(nW) algorithm for subset sum mean P equals NP?

No. The target W is written in binary, so the input contains only about log W bits for it, and a running time that grows with the value of W can be exponential in the input length. Such an algorithm is called pseudo-polynomial, and subset sum remains NP-complete.

What is the difference between NP-hard and NP-complete?

A problem is NP-hard when every problem in NP reduces to it in polynomial time; it need not be in NP itself and need not be a decision problem. A problem is NP-complete when it is NP-hard and also belongs to NP, so its yes answers have short certificates that can be checked in polynomial time.

Study strategy

Exam move

Write the two-part template for an NP-completeness proof from memory, then apply it to clique and to one problem of your own choice. Redraw the 3-SAT gadget for a new formula and check both directions on it. Finally list the lecture's reduction tree with one sentence describing each arrow. In the final week, practise one full reduction under time pressure, writing the five labelled parts in order without notes.

Practise saying in one sentence why each gadget forces the property it is designed to force.

Working through NP-Completeness and Polynomial-Time Reductions in COMPSCI320? Sia is AskSia’s AI Computer Science tutor — ask any COMPSCI320 NP-Completeness and Polynomial-Time Reductions question and get a clear, step-by-step explanation grounded in how COMPSCI320 is taught and assessed. Read this chapter free, then take your hardest questions to Sia.

A+Everything unlocked
Unlocks this Bible + all 34 of your University of Auckland subjects - and 1,000+ Bibles across every Australian university.
Sia - your COMPSCI320 tutor, unlimited, worked the way the exam marks it
The full 5-page Bible + practice bank with worked solutions
Chrome extension - sync your LMS so Sia knows your deadlines
Bilingual EN / Chinese on every Bible and every Sia answer
$0.99 Trial
30-day money-back · cancel in one tap · how it works