COSC 341: Lecture 21
1
Graph Theoretic NP-complete Problems
Introduction
• The vertex cover problem
• Proving that VC is NP-complete
• A typical NP-completeness argument
• Other graph theory problems
• Fixed parameter tractability
2
NP-complete problems in graph theory
There are hundreds of NP-complete problems. For a recent selection see http://www.
csc.liv.ac.uk/˜ped/teachadmin/COMP202/annotated_np.html Also, see the
book M. R. Garey and D. S. Johnson. Computers and intractability. A Guide to the theory of
NP-completeness. WH Freeman and Company, New York, 1979.
Historically, graph theoretic problems were among the earliest to be proved NP-complete.
We’ll start by looking at one of the very first such problems: the Vertex Cover problem.
All NP-completeness results are proved in the same way
1. Prove the problem lies in the class NP
2. Find an NP-complete problem that reduces to it.
3
The Vertex Cover problem
Definition 3.1 (Vertex Cover). Given a graph (V, E) and an integer k does there exist a
set C of k vertices such that every edge has one (or both) endpoints in the set C? The set
C is called a vertex cover.
Theorem 3.2. The vertex cover problem is NP-complete.
Proof. The first part of the proof is usually easiest.
3.1
Vertex cover in N P
It is fairly obvious that the vertex cover problem is in N P. Simply choose a set of k
vertices non-deterministically then check if all edges are covered by those vertices (clearly
polynomial).
1
COSC 341: Lecture 21
3.2
Graph Theoretic NP-complete Problems
Reduce 3-SAT to VC
For the second step we must find some suitable NP-complete problem – at this stage in
our experience there isn’t much choice!!
This means: find a function f that maps instances of 3-SAT into instances of VC such that
• Given an arbitrary instance I of 3-SAT f (I) will be an instance of VC, i.e. f (I) will
be a graph G together with an integer k, i.e. f (I) = (G, k)
• f (I) can be computed in polynomial time in |I|
• f (I) will be a positive instance if and only if I is a positive instance (i.e. G will have
a vertex cover of k vertices if and only if the clauses of I are satisfiable)
We now define the function f by a construction that, given I, produces G and k
Suppose the variables of I are x1 , x2 , . . . , xn and there are m clauses in the boolean formula:
(u11 ∨ u12 ∨ u13 ) ∧ (u21 ∨ u22 ∨ u23 ) ∧ . . . ∧ (um1 ∨ um2 ∨ um3 )
The variables uij are literals and could be any one of xk . The i, j labels refer to the particular position of the literal in the boolean formula.
3.2.1
Making G
There is one vertex for every xi , one vertex for every ¬xi , and one vertex for every uij .
There is an edge from vertex xi to vertex ¬xi (all values of i). There is an edge between
vertex uij and vertex uik (all values of i and all values j, k with j 6= k). There is an edge
from xi to ujk exactly when xi = ujk , and an edge from ¬xi to ujk exactly when ¬xi = ujk .
See Figure 1 for an example of G.
3.2.2
Making k
Define k = n + 2m.
All this can be done in time polynomial in the size of I (in fact in time O(mn) which is
quadratic in |I|).
3.2.3
The clauses are satisfiable =⇒ there is a vertex cover
Suppose we have a satisfying assignment. We find the vertex cover as follows:
• if xi = T put vertex xi in the vertex cover
2
COSC 341: Lecture 21
x1
Graph Theoretic NP-complete Problems
¬x1
x2
¬x2
x3
u12
¬x3
x4
¬x4
u22
u11
u21
u13
u23
k = n + 2m = 4 +2+2 = 8
Figure 1: Reduction of (x1 ∨ ¬x2 ∨ x3 ) ∧ (¬x1 ∨ x2 ∨ ¬x4 )
• if xi = F put vertex ¬xi in the vertex cover
At this point we have used up n vertices and have covered the n edges from xi to ¬xi
(and some others too).
For each triple of vertices uj1 , uj2 , uj3 we have three edges leading to an x or a ¬x. At least
one of these will already be covered; the one corresponding to the true value in the clause.
To cover the two remaining edges of the three, and the edges of the triangle uj1 , uj2 , uj3
we put an appropriate two vertices of the triangle in the vertex cover.
3.2.4
There is a vertex cover =⇒ the clauses are satisfiable
Suppose we have a vertex cover.
From the form of the graph the cover must have exactly one vertex from each pair
{xi , ¬xi }. That’s n of the vertices.
The other 2m vertices must be used 2 per triangle to cover the triangle edges.
We consider the truth assignment
• Define xi = T if vertex xi is in the cover.
• Define xi = F if vertex ¬xi is in the cover.
Consider the clause corresponding to the vertices uj1 , uj2 , uj3 and the vertex of this trio
not in the vertex cover. That vertex is connected to a vertex xi or ¬xi that must be in the
cover which therefore has the value T; so the clause contains a true value.
3
COSC 341: Lecture 21
Graph Theoretic NP-complete Problems
x1
¬x1
x2
¬x2
x3
u12
u11
¬x3
x4
¬x4
u22
u21
u13
u23
k = n + 2m = 4 +2+2 = 8
Figure 2: Vertex cover corresponding to x1 = T, x2 = F, x3 = T, x4 = F
4
An “efficient” algorithm to solve VC
Observation 4.1.
1. We can always remove isolated vertices.
2. In finding a vertex cover with at most k vertices we must put every vertex of degree
greater than k in the vertex cover.
Therefore we can find a vertex cover (if one exists) as follows:
1. Put all vertices of degree greater than k in the cover and remove them from the
graph. Call the number of such vertices g. This leaves a smaller graph for which
we want a vertex cover with k 0 = k − g vertices.
2. Repeat step 1 for this graph until we can go no further
3. Remove isolated vertices
4. Now solve VC problem for a graph Ĝ and cover size k̂, where Ĝ has all vertices of
degree at most k̂ and no isolated vertices
If Ĝ has more than k̂ 2 edges then no vertex cover of k̂ vertices.
If at most k̂ 2 edges then also at most 2k̂ 2 vertices. At this point we can use brute force.
Since the number of vertices left is independent of the original number of vertices, the
brute force part of the algorithm is independent of n. In fact, it is linear in n (step 1 of the
2
algorithm above). But the brute force is exponential in k (there are 22k̂ subsets of vertices
to check. We say VC is fixed-parameter tractable in n — Downey and Fellows.
4
COSC 341: Lecture 21
5
Graph Theoretic NP-complete Problems
Tutorial Problems
Question 1
Consider the conjunction of clauses
(x1 ∨ x2 ∨ x3 ) ∧ (¬x1 ∨ ¬x2 ) ∧ (x1 ∨ ¬x2 ∨ ¬x3 )
Give the graph constructed in the reduction of 3-SAT to VC. Find a vertex cover of this
graph with at most 9 vertices and read off a satisfying assignment.
Question 2
Consider the following two problems:
• UHAM: an instance of this problem is an undirected graph. The decision question is
whether G has a Hamiltonian circuit (a sequence of edges that visits all the vertices
once only, returning to the initial vertex).
• DHAM: an instance of this problem is a directed graph. The decision question is
whether G has a Hamiltonian circuit (a sequence of directed edges that visits all the
vertices once only, returning to the initial vertex).
1. Prove that both these problems are in N P .
2. Find a polynomial time reduction of UHAM to DHAM.
3. Find a polynomial time reduction of DHAM to UHAM.
Notes:
The first of these is easy – no hints, except to remind you that to be in N P is simply to
have a polynomial time “guess and check” algorithm.
For the second and third you have to take an instance of one and, in polynomial time,
produce an instance of the other with the same answer.
The second is easy – no further hints at all!
The third is not too bad: think about replacing a vertex with three vertices joined in a
path.
Actually, both these problems are N P -complete (there is a polynomial time reduction of
3-SAT to DHAM in the textbook). Here’s a similar looking problem:
Question 3
EulerPath: Given a graph, find a sequence of edges giving you a path through the graph
that visits every edge exactly once, returning to the start.
What are your thoughts? In P ? In N P ? N P -complete?
5
© Copyright 2026 Paperzz