CMPT-705: Design and Analysis of Algorithms
Spring ’08
Chapter 10 — Coping with NP-Completeness
Lecturer: Binay Bhattacharya
Scribe: Baskaran Sankaran
Continuing with the discussions on NP-Completeness, this lecture addresses the question, “Are these problem always hard?”. The question motivates us to think if the problem size or any other parameter has any bearing
on the practical solvability of these problems.
10.1
Parameterized Algorithms
These algorithms depend on a problem parameter k. Generally the algorithm
running time is exponential on k but not on the input size. Hence for smaller
valued of k we have a tractable solution. For example, let us consider the
vertex-cover problem:
10.1.1
Vertex Cover problem
Given a graph G = (V, E) and an integer k, is there a subset
S ⊆ V such that, |S| ≤ k and every edge e ∈ E is incident on at
least one node u ∈ S.
We have earlier seen this to be NP-complete problem. However, for
smaller values of k, a closer analysis of the problem will show it to be a
bit easier. When k is small, we can use brute force approach in combination with the NP certifier to solve it in O(k ∗ nk+1 ), as explained below in
algorithm 1
Algorithm 1 Brute force algorithm for Vertex-Cover problem
brute force vertex-cover(G,k)
1: Enumerate all possible subsets of size k; total nk subsets
2: for each subset Si : do
3:
Use polynomial time certifier to verify if Si is a vertex cover of G in
O(kn) time
4: end for
10-1
CMPT-705 Chap 10 — Coping with NP-Completeness Spring ’08
Interestingly it is possible to solve vertex-cover in O(2k kn) time,
which clearly is better than the brute force algorithm illustrated above. We
will consider two claims now, before we see discuss a O(2k kn) time algorithm.
Claim 10.1.1. Let (u, v) be an edge of G. G has a vertex cover of size at
least k, if and only if either G − {u} or G − {v} has a vertex cover of size
≤ k − 1.
Proof: If G has a vertex cover of size k, then S must contain at least one
of them u or v. If we assume u ∈ S then G − {u} will have a vertex cover
|S − {u}| of size k − 1. Similarly, this is true for v ∈ S.
Coversely, if we assume S to be a vertex cover of G − {u} of size k − 1,
then inclusion of u will add a new vertex with edges incident on it. Thus
S ∪ {u} will be the vertex cover of size ≤ k for G.
Claim 10.1.1. G has a vertex cover of size k, if and only if G has at most
k(n − 1) edges.
We can now elaborate the algorithm, which becomes clearer based on the
above claims. It is based on a simple dynamic programming formulation and
it tries to solve the vertex-cover by repeatedly eliminating the edges in
G one by one. For every edge deleted, we note (from Claim 10.1.1) that at
least one of the two nodes of the edge must be in vertex cover if G has a
vertex cover of size k.
Algorithm 2 Vertex-Cover
boolean vertex-cover(G,k)
1: If G has vertex cover of size 1, then Return TRUE
2: If G has ≥ kn edges, then Return FALSE
3: Let (u, v) be an edge of G
4: Remove u and the edges incident on it to find vertex cover of G − {u},
a = vertex-cover(G − {u}, k − 1)
5: Remove v and the edges incident on it to find vertex cover of G − {v},
b = vertex-cover(G − {v}, k − 1)
6: Return a ∨ b
The algorithm finally returns a set of nodes S of size k, if G has a vertex cover of the same size. Now, let us determine the running time of the
algorithm by formulating the recurrence relation for the algorithm.
10-2
CMPT-705 Chap 10 — Coping with NP-Completeness Spring ’08
T (n, k) = 2 ∗ T (n − 1, k − 1) + ckn
≤ 2 ∗ T (n, k − 1) + ckn
∈ O(2k kn)
10.2
Solving NP-Complete problems in Trees
Consider the optimization version of the following problems: i) independent
set, ii) clique, iii) vertex cover and iv) graph colouring. We proved that these
problems to be NP-complete for Graphs. However, if we consider these problems in Trees, they become surprisingly simpler and efficient algorithms have
already been developed for them. We will show an example for independent
set problem in trees and it will become simpler for other problems.
10.2.1
Independent set in Trees
Consider the tree T below rooted at top by node say ’root’ and if this node
is part of the independent set S, then the nodes labelled l and r will not be
part of the set S as they are connected by an edge. Thus it can be observed
that nodes at adjacent levels can not be part of an independent set of the
tree T .
The problem of finding a largest independent set can be solved by a simple dynamic programming formulation. Let us define:
IS1 (Tu ): Largest independent set in Tu that includes node u
IS2 (Tu ): Largest independent set in Tu that does not include node u
From these definitions, we can write the expression for largest independent set starting from the ’root’ node as:
Largest independent set = Largest(IS1 (Troot ), IS 2 (Troot ))
Rewriting the definitions in recursive form, we have:
IS1 (Troot ) = {root} ∪ IS2 (Tl ) ∪ IS2 (Tr )
IS2 (Troot ) = IS1 (Tl ) ∪ IS1 (Tr )
10-3
CMPT-705 Chap 10 — Coping with NP-Completeness Spring ’08
root
r
l
Figure 10.1. NP-Completeness in Trees
This returns the largest independent set in polynomial time as can be
realized from this formulation. It is now easy to see that the vertex cover
problem on a Tree T can be solved in a similar way and the minimum vertex
cover would be: V − |ISmax |.
Earlier we saw that the colouring of the bipartite graph is a polynomial
algorithm. The tree colouring problem also becomes tractable when we notice
the fact that every tree is a bipartite graph and hence can be coloured easily.
Consider a bipartite graph G = (X ∪ Y, E); G has following properties:
• G is 2-colourable
• It has a clique of size 2
• If M is the maximum matching of G then its maximum independent
set, ISmax = n − |M |
10.3
Problems in Interval Graphs
We have seen the different flavours of interval problems including interval
scheduling. The class of interval problems can be represented as graphs
called as interval graphs and exhibit certain chracteristics that are absent in
general graph problems. In this section we will see how the set of intervals
are represented in graphs and also see some general ideas on how the usual
10-4
CMPT-705 Chap 10 — Coping with NP-Completeness Spring ’08
NP-complete problems as independent set, clique etc. are tackled in interval
graphs.
10.3.1
Set of intervals in a line
Formally, given n intervals S = {I1 .I2 , . . . In } on a line L. The interval graph
G(S) is a graph where each interval is a vertex in G(S) such that two vertices
in the graph are connected by a edge if and only if the corresponding intervals
overlap.
Figure 10.2. Interval Graph Representation
Assuming an interval graph G(S), the following problems are solvable
in polynomial time. The list also gives the hints to be used in solving the
problems.
• Independent set : Using DP
• Vertex cover : V − |ISmax |
• Clique : Depth of the set
10-5
CMPT-705 Chap 10 — Coping with NP-Completeness Spring ’08
• Colouring : Colourable by d colours, where d is the depth
10.4
Problems in Circular Arc Graphs
Circular arc graphs is the graph representation of the set of arc intervals
on a circle, which has also been studied earlier in the course. An example
representation of circular arcs given by the set C = {c1 , c2 , . . . cn } and the
corresponding graph G(C) is shown below.
Figure 10.3. Circular arc graph representation
To solve the independent set of the graph G(C), we can again use dynamic
10-6
CMPT-705 Chap 10 — Coping with NP-Completeness Spring ’08
programming as we did for the intervals in the line. For this, select a random
node c1 and this will have two possibilities, viz. c1 is in the independent set
or it is not and these cases are listed below for clarity.
• If c1 is in the IS, the all the other arcs overlapping with it can’t be in
the IS. So, excluding arc c1 and its overlapping arcs, other arcs can be
treated as intervals in the line and can be solved using the dynamic
programming algorithm explained earlier.
• If c1 is not in the IS, then we solve for it for other arcs, (i.e) C − {c1 }
In the case of circular arc graphs the clique is not always equal to the
depth as we saw in the case of interval graphs. Circular arc graphs have
clique size at least equal to the depth. The clique size of G(C) can easily be
found in O(n3 ) time and a O(m + n log n) solution is possible, where m is
the number of edges in G(C).
The vertex cover of G(C) will be C − |ISmax | and it should be noted that
this is similar to the interval graphs case.
The colouring problem of circular graphs, however is NP-Complete problem. The problem can be formally stated as: Is a circular arc graph representing a given circular arc model k-colourable? A O(nk!) solution has
been proposed for circular arc graph colouring problem and the algorithm is
practical for small values of k.
10-7
© Copyright 2026 Paperzz