lecture on graphs and algorithms (master 1)lecture on graphs and algorithms (master 1) nicolas nisse...

45
Lecture on Graphs and Algorithms (Master 1) Nicolas Nisse * Abstract These are lecture notes of the course I gave, at Master 1 level. The main topic is the design of algorithms for solving NP-hard problems, mostly in graphs. Contents I Introduction 2 1 Informal Introduction 2 2 Basics on Graphs [2, 5] 3 2.1 P vs. NP -hard, a first example: Eulerian vs. Hamiltonian ............. 4 2.2 Trees, subgraphs and spanning trees (Kruskal’s algorithm) ............. 6 2.3 Matching and Vertex Cover in graphs ........................ 7 2.3.1 Matchings in bipartite graphs (Hall’s theorem, Hungarian’s method) . . . 9 2.3.2 Vertex Cover in graphs (K¨ onig’s theorem and 2-approximation) ...... 10 II Approximation Algorithms [8] 12 3 Introduction to Approximation Algorithms: Load balancing 12 3.1 Definition of an Approximation Algorithm ...................... 12 3.2 The Load Balancing Problem ............................. 13 3.2.1 Greedy 2-Approximation (least loaded processor) .............. 13 3.2.2 Greedy 3 2 -Approximation (least loaded processor and ordered tasks) ... 15 4 Traveling Salesman Problem (TSP) 16 4.1 Different variants and exact dynamic programming algorithm ........... 16 4.2 2-Approximation (using minimum spanning tree) .................. 18 4.3 3 2 -Approximation (Christofides’algorithm) ...................... 19 5 Set Cover 19 5.1 Relationship with Graphs: Dominating Set and Vertex Cover ........... 20 5.2 Greedy O(log n)-approximation ............................ 21 6 Knapsack and (F)PTAS 23 6.1 (Pseudo-polynomial) Exact Algorithm via dynamic programming ......... 23 6.2 Greedy 2-Approximation and PTAS ......................... 24 * Universit´ e Cˆ ote d’Azur, Inria, CNRS, I3S, France 1

Upload: others

Post on 08-Dec-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lecture on Graphs and Algorithms (Master 1)Lecture on Graphs and Algorithms (Master 1) Nicolas Nisse Abstract These are lecture notes of the course I gave, at Master 1 level. The main

Lecture on Graphs and Algorithms (Master 1)

Nicolas Nisse∗

Abstract

These are lecture notes of the course I gave, at Master 1 level. The main topic is thedesign of algorithms for solving NP-hard problems, mostly in graphs.

Contents

I Introduction 2

1 Informal Introduction 2

2 Basics on Graphs [2, 5] 32.1 P vs. NP -hard, a first example: Eulerian vs. Hamiltonian . . . . . . . . . . . . . 42.2 Trees, subgraphs and spanning trees (Kruskal’s algorithm) . . . . . . . . . . . . . 62.3 Matching and Vertex Cover in graphs . . . . . . . . . . . . . . . . . . . . . . . . 7

2.3.1 Matchings in bipartite graphs (Hall’s theorem, Hungarian’s method) . . . 92.3.2 Vertex Cover in graphs (Konig’s theorem and 2-approximation) . . . . . . 10

II Approximation Algorithms [8] 12

3 Introduction to Approximation Algorithms: Load balancing 123.1 Definition of an Approximation Algorithm . . . . . . . . . . . . . . . . . . . . . . 123.2 The Load Balancing Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

3.2.1 Greedy 2-Approximation (least loaded processor) . . . . . . . . . . . . . . 133.2.2 Greedy 3

2 -Approximation (least loaded processor and ordered tasks) . . . 15

4 Traveling Salesman Problem (TSP) 164.1 Different variants and exact dynamic programming algorithm . . . . . . . . . . . 164.2 2-Approximation (using minimum spanning tree) . . . . . . . . . . . . . . . . . . 184.3 3

2 -Approximation (Christofides’algorithm) . . . . . . . . . . . . . . . . . . . . . . 19

5 Set Cover 195.1 Relationship with Graphs: Dominating Set and Vertex Cover . . . . . . . . . . . 205.2 Greedy O(log n)-approximation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

6 Knapsack and (F)PTAS 236.1 (Pseudo-polynomial) Exact Algorithm via dynamic programming . . . . . . . . . 236.2 Greedy 2-Approximation and PTAS . . . . . . . . . . . . . . . . . . . . . . . . . 24

∗Universite Cote d’Azur, Inria, CNRS, I3S, France

1

Page 2: Lecture on Graphs and Algorithms (Master 1)Lecture on Graphs and Algorithms (Master 1) Nicolas Nisse Abstract These are lecture notes of the course I gave, at Master 1 level. The main

III Parameterized Algorithms [4] 26

7 Introduction to Parameterized Algorithms (with Vertex Cover as toy example) 267.1 First Approach: deciding if vc(G) ≤ k? . . . . . . . . . . . . . . . . . . . . . . . . 277.2 Fixed Parameter Tractable (FPT) Algorithms and Kernelization . . . . . . . . . 297.3 A first Kernelization Algorithm for Vertex Cover . . . . . . . . . . . . . . . . . . 30

8 Toward tree-decompositions, Graph Minor Theory and beyond 318.1 Minimum (weighted) Vertex Cover in trees . . . . . . . . . . . . . . . . . . . . . 318.2 2-trees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328.3 k-trees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358.4 Brief introduction to treewidth and tree-decompositions . . . . . . . . . . . . . . 368.5 Graph Minor theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

Part I

Introduction

1 Informal Introduction

The main goal of this lecture is to present some ways/techniques/methods to design efficientalgorithms (and their analysis) to solve optimization problems (mainly in the graph context).Note that Section 8 is clearly beyond the scope of this lecture but aims at going further intoalgorithmic graph theory.

This introduction is only an intuition of what will be addressed in the lecture (most of theconcepts will be more formally defined and examplified later).

Tradeoff between time complexity and quality of the solution. What is an efficientalgorithm? Some problems have a unique solution (e.g., sorting a list of integer), some otherproblems have several valid (≈ correct) solutions but only some of them are optimal (e.g. findinga shortest path between two vertices in a graph: there may be many paths, but only few ofthem may be shorter).

Here, we measure the efficiency as a tradeoff between the “time” to get a valid/correctsolution (time-complexity) and the “quality” of a valid solution (how “far” is it from anoptimal solution?).

Difficult vs. Easy Problems. We assume here that readers are familiar with basics on timecomplexity of algorithms. If not, see [3] or here (in french, on polynomial-time algorithms) forprerequisite background.

Very informally, problems may be classified into

P. Class of problems for which we know a Polynomial-time algorithm (polynomial in the sizeof the input) to solve them.

NP. Class of problems for which we know a Non-deterministic Polynomial-time algorithm tosolve them. Equivalently, it can be checked in (deterministic) polynomial-time whether asolution to such problem is valid/correct. (Clearly, P ⊆ NP )

NP-hard. Class of problems that are “as hard as the hardest problems in NP”. I don’t wantto give a formal definition of it here. Informally, you should understand this class of

2

Page 3: Lecture on Graphs and Algorithms (Master 1)Lecture on Graphs and Algorithms (Master 1) Nicolas Nisse Abstract These are lecture notes of the course I gave, at Master 1 level. The main

problems as the ones for which nobody currently knows a deterministic polynomial-time algorithm to solve them (related to the question whether P = NP , a question thatworths 1.000.000 dollars). Intuitively (not formally correct), the best known algorithmsfor solving such problems consist of trying all possibilities...

In what follows, I refer to problems in P as “easy” and to NP -hard problems as “difficult”.The main question I try to address in this lecture is how to deal with difficult problems. Weprobably (unless P = NP ) cannot solve them “efficiently” (in polynomial time)... so, shouldwe stop trying solving them? NO !!! there are many ways to tackle them and the goal of thislecture is to present some of these ways. Roughly, we will speak about:

1. Better exponential exact algorithms. “Try all possibilities in a more clever way” [6]

2. Approximation algorithms. Design poly-time algo. for computing solution (not nec-essarily optimal) with “quality’s guaranty” (“not far from the optimal”) [8]

3. Restricted graph classes. “Use specifities of inputs” [4, 8]

4. Parameterized algorithms. (formal definition will be given later) [4]

First, I want to give some basics on graph theory. The main reasons for it is that: (1) graphsare a natural (and nice) mathematical model to describe many real-life problems, and (2), wewill then mainly consider graph problems as examples (so, we need a common backgroundon graphs structural results and algorithms). Then, this lecture will try to address severaltechniques (mentioned above) to deal with difficult problems (mostly in graphs).

2 Basics on Graphs [2, 5]

A graph G is a pair G = (V,E) where V is a set1 of elements and E ⊆ V × V is a relationshipon V . Any element of V is called vertex. Two vertices u, v ∈ V are “linked” by an edge u, vif u, v ∈ E, in which case u and v are said adjacent or neighbors. So V is the set of verticesand E is the set of edges.2

Intuition. It can be useful (actually, IT IS!!) to draw graphs as follows: each vertex can bedepicted by a circle/point, and an edge between two vertices can be drawn as a curve (e.g., a(straight) line) linking the corresponding circles/points.Graphs are everywhere. As examples, let us consider a graph where vertices are: cities, pro-teins, routers in the Internet, people,... and where two vertices are linked if they are: linked by aroad (road networks), by some chemical interaction (biological networks), by optical fiber (com-puter networks/Internet), by friendship relationship (social networks: Facebook, Twitter...).

Notation. For v ∈ V , let N(v) = w ∈ V | v, w ∈ E be the neighborhood of v (set of itsneighbors) and N [v] = N(v) ∪ v be its closed neighborhood. The degree of a vertex v ∈ V isthe number deg(v) = |N(v)| of its neighbors. Given a graph G, if V and E are not specified,let E(G) denote its edge-set and let V (G) denote its vertex-set.

Proposition 1 Let G = (V,E) be any simple graph: |E| ≤ |V |(|V |−1)2 and∑v∈V

deg(v) = 2|E|.

1In what follows, we always assume that V is finite, i.e., |V | is some integer n ∈ N.2Technical remark. Unless stated otherwise, in what follows, we only consider simple graphs, i.e., there are

no loops (i.e., no vertex is linked with itself, i.e., v, v /∈ E for every v ∈ V ) nor parallel edges (i.e., there is atmost one edge between two vertices).

3

Page 4: Lecture on Graphs and Algorithms (Master 1)Lecture on Graphs and Algorithms (Master 1) Nicolas Nisse Abstract These are lecture notes of the course I gave, at Master 1 level. The main

Proof. We prove that∑v∈V

deg(v) = 2|E| by induction on |E|. If |E| = 1, then G must have two

vertices with degree 1, and all other with degree 0. So the result holds. Assume by inductionthat the result holds for |E| ≤ k and let assume that |E| = k + 1. Let a, b ∈ E and letG′ = (V,E \ a, b) be the graph obtained from G by removing the edge a, b. By induction,∑v∈V

degG′(v) = 2|E(G′)| = 2(|E| − 1). Since∑v∈V

degG(v) =∑v∈V

degG′(v) + 2 (because the edge

a, b contributes for 2 in this sum), the result holds. Let n = |V |.Since each vertex has degree at most n− 1, 2|E| =

∑v∈V

deg(v) ≤∑v∈V

(n− 1) = n(n− 1).

A Walk in a graph G = (V,E) is a sequence (v1, · · · , vk) of vertices such that two consecutivevertices are adjacent (i.e., for every 1 ≤ i < k, vi, vi+1 ∈ E). A Trail is a walk where no edgesare repeated. A trail is a Tour if the first and last vertex are equal. A tour is Eulerian if it useseach edge of G exactly once.

A Path is a walk with no repeated vertex. Finally, a Cycle is a tour with no repeated vertex(except that the first and last vertices are equal). A cycle is Hamiltonian if it meets everyvertex of G exactly once.Note that, a path is a trail, and a trail is a walk (but not all walks are trails, not all trails arepaths). Similarly, a cycle is a tour, and a tour is a walk (not all walks are tours, not all toursare cycles).

Exercise 1 Give examples of graphs that are

• Eulerian (that admits a Eulerian tour) AND Hamiltonian (admits an Hamiltonian cycle)3;

• not Eulerian AND Hamiltonian;

• Eulerian AND not Hamiltonian;

• not Eulerian AND not Hamiltonian.

At a first glance, the problem of deciding whether a graph is Eulerian and the problem ofdeciding whether a graph is Hamiltonian look very similar. From the complexity point of viewit seems they are quite different.

2.1 P vs. NP -hard, a first example: Eulerian vs. Hamiltonian

A graph G = (V,E) is connected if, for every two vertices u, v ∈ V , there is a path connectingu to v. Note that, to admit a Eulerian or Hamiltonian cycle, a graph must be connected. So,in what follows, we only focus on connected graphs. Given v ∈ V , the connected component ofG containing v is the graph (Vv, E ∩ (Vv×Vv)) where Vv is the set of all vertices reachable fromv in G.

The following algorithm decides whether a graph is Hamiltonian. For this purpose, it con-siders one after the other every permutation of V (all possible ordering of the n vertices) andchecks if this permutation corresponds to a cycle.

There are n! permutations of V 4 so, in the worst case, there are n! iterations of the for-loop.At each iteration, the algorithm checks n edges to verify if the current permutation is a cycle.Overall, the time-complexity is then O(n · n!). In this course, we will see other (much better)

3Formally, a graph reduced to a single vertex is a pathological case of a graph with both a Eulerian cycle andan Hamiltonian cycle (both reduced to this single vertex). Try to find examples with more vertices.

4For any set with n elements, there are n! orderings of these elements. Indeed, there are n choices for the firstelement, n− 1 for the 2nd one, n− 2 for the 3rd one, and so on, so n(n− 1)(n− 2) · · · 2 · 1 = n! in total.

4

Page 5: Lecture on Graphs and Algorithms (Master 1)Lecture on Graphs and Algorithms (Master 1) Nicolas Nisse Abstract These are lecture notes of the course I gave, at Master 1 level. The main

Algorithm 1 Naive algorithm for Hamiltonicity

Require: A connected graph G = (V,E).Ensure: Answers Y es is G is Hamiltonian and No otherwise.

1: for each permutation of V do2: if the permutation corresponds to a cycle then3: return Y es.4: end if5: end for6: return No

algorithms for this problem, but all have at least exponential time-complexity. Roughly, theonly way we know is to try all possibilities. Indeed, it can be proved (I will not do it here) thatthe problem of deciding whether a graph is Hamiltonian is NP -hard! [7]

The other problem is very different.

Theorem 1 [Euler 1736] A graph admits an Eulerian cycle iff all vertices have even degree.

Before proving this theorem, let us look at its consequence.

Algorithm 2 Algorithm for deciding of a graph is Eulerian

Require: A connected graph G = (V,E).Ensure: Answers Y es is G is Eulerian and No otherwise.

1: for every v ∈ V do2: if v has odd degree then3: return No.4: end if5: end for6: return Y es

There are n iterations and each of them just checks the degree of one vertex. Overall, thecomplexity is O(

∑v∈V deg(v)) which is O(|E|) by proposition above. Therefore, the problem

of deciding whether a graph has an Eulerian cycle is in P .Proof.[Sketch of proof of Th. 1] Assume that G is Eulerian and let v ∈ V . Each time the cyclereaches v by some edge, it must leave by another (not used yet) edge. Hence, v has even degree.

Now, let us assume that every vertex has even degree. The proof is constructive (it producesa Eulerian cycle). Let us sketch a recursive algorithm that computes an Eulerian cycle.

1. First, start from any vertex v and greedily progress along the edges. Each time a newvertex is reached, it is possible to leave it since its degree is even (and so it remains atleast one non-used edge). Since a graph is finite, eventually, this greedy walk reaches avertex that has already been visited and so, we found a cycle C = (v1, · · · , vr).

2. Let G′ be the graph obtained by removing from G every edge of C. Let G′1, · · · , G′k be theconnected components of G′. Removing the edges of C, every vertex of C has its degreereduced by exactly two. So, for every i ≤ k, every vertex of G′i has even degree and, byinduction on the number of edges, G′i has a Eulerian cycle. By applying recursively thealgorithm on G′i, let C′i be the Eulerian cycle obtained for G′i.

3. A Eulerian cycle of G is obtained by starting from v1, following C and, each time it meetsa vertex vj (j ≤ r), it follows the Eulerian cycle of the connected component of G′ thatcontains vj (if not yet met). Prove that it is actually a Eulerian cycle.

5

Page 6: Lecture on Graphs and Algorithms (Master 1)Lecture on Graphs and Algorithms (Master 1) Nicolas Nisse Abstract These are lecture notes of the course I gave, at Master 1 level. The main

Note that this algorithm has roughly time-complexity O(|E||V |) (finding a cycle takes timeO(|V |) and, in the worst case, has size 3 and so decreases by 3 the number of edges).

Note that, previous proof shows that, not only it can be decided if a graph is Eulerian inpolynomial-time, but also an Eulerian cycle (if any) can be found in polynomial-time.

2.2 Trees, subgraphs and spanning trees (Kruskal’s algorithm)

A Tree is any acyclic (with no cycle) connected graph.A Subgraph of G is any graph that can be obtained from G by removing some edges and

some vertices. Hence, a subgraph of G = (V,E) is any graph H = (V ′, E′) with V ′ ⊆ V andE′ ⊆ E ∩ (V ′ × V ′). If V ′ = V , then H is a spanning subgraph. A spanning tree of G is aspanning subgraph which is a tree.

Exercise 2 Let G = (V,E) be any graph. Show that:

• if G is a tree, there is a unique path between any two vertices of G;

• if G is a tree, then |E| = |V | − 1;

• G admits a spanning tree if and only if G is connected;

• deduce from previous items that, G is connected ⇒ |E| ≥ |V | − 1;

• if G is acyclic and |E| = |V | − 1, then G is a tree;

• if G is connected and |E| = |V | − 1, then G is a tree;

Given X ⊆ V , the subgraph (of G) induced by X is the subgraph G[X] = (X,E ∩ (X ×X)). IfF ⊆ E, the graph induced by F is G[F ] = (

⋃u,v∈F u, v, F ).

Let w : E → R∗+ be a weight function on the edges. The weight of a subgraph G[F ] inducedby F ⊆ E is

∑e∈F w(e). The goal of this section is the computation of a connected spanning

subgraph with minimum weight.

Exercise 3 Let (G,w) be a graph with an edge-weight function. Show that any minimum-weightspanning connected subgraph is a spanning tree.

Proof. Let H be a minimum spanning connected subgraph. If H contains no cycle, it isa tree. Otherwise let C be a cycle in H and let e ∈ E(C) be any edge of E. Show that(V (H), E(H) \ e) is a connected spanning subgraph of G. Conclusion?

Above exercise somehow justifies the interest of minimum spanning tree in a practical pointof view. For instance, assume you want to connect some elements of a network (cities connectedby roads, buildings connected by electrical cables, etc.) and that weights on the links representthe price of building them. Then, a minimum spanning tree will be the cheapest solution.

Let’s compute it!The first step (ordering the edges) takes time O(m logm)5. Then there are at most m

iterations of the for-loop. Each iteration takes time O(1) (by using suitable data structure suchas Union-Find). Overall, the time-complexity of the algorithm of Kruskal is O(m logm).

Theorem 2 The Kruskal’s algorithm returns a minimum spanning tree of G.

5Recall that ordering a set of n elements takes time O(n logn) (e.g., merge-sort)

6

Page 7: Lecture on Graphs and Algorithms (Master 1)Lecture on Graphs and Algorithms (Master 1) Nicolas Nisse Abstract These are lecture notes of the course I gave, at Master 1 level. The main

Algorithm 3 : Kruskal’s Algorithm (1956)

Require: A (non-empty) connected graph G = (V,E) and w : E → R∗+.Ensure: A minimum spanning tree T of G.

1: Order E in non decreasing order: w(e1) ≤ w(e2) ≤ · · · ≤ w(em).2: Let v ∈ V and T = (v, ∅).3: for i from 1 to m do4: if If T is connected and spanning then5: return T .6: end if7: Let ei = u, v.8: if (V (T ) ∪ u, v, E(T ) ∪ ei) is acyclic then9: T ← (V (T ) ∪ u, v, E(T ) ∪ ei).

10: end if11: end for

Proof. Let T be the spanning tree computed by the algorithm. Let (ei1 , ei2 , · · · , ein−1) be theedges of T ordered in non-decreasing order of their weights. Let T ∗ be a minimum spanningtree minimizing |E(T ∗)∩E(T )|. If T ∗ = T , we are done. Otherwise, let j < n be the minimumindex such that eij ∈ E(T ) \ E(T ∗) (why it exists?). Note that E(T ∗) ∩ e1, e2, · · · , eij =ei1 , ei2 , · · · , eij−1 by def. of j and of the algorithm. Let eij = u, v and let P be the uniquepath from u to v in T ∗ (why it exists?). Show that P contains an edge f /∈ E(T ) such thatw(f) ≥ w(eij ). Show that (T ∗ \ f) ∪ eij is a minimum spanning tree of G. Conclusion?

As we will see in the following of the lecture, computing a minimum spanning tree of a graphis one important basic blocks of many graph algorithms!!

2.3 Matching and Vertex Cover in graphs

Graphs are a very useful tool to deal with allocation problems. For instance, consider a set ofstudents that have to choose an internship among a set of proposals. Each student and proposalmay be modeled as vertices of a graph and a student is linked to a proposal if it has some interestfor it. How to assign internships to students so that at most one student is assigned to eachproposal and every student gets an internship that interests him/her? Say differently, how tomatch internships and students? This is the topic of this subsection.

Let G = (V,E) be a graph. A matching in G is a set M ⊆ E of edges such that e ∩ f = ∅for every e 6= f ∈M . That is, a matching is a set of edges pairwise disjoint.

A matching M is perfect is all vertices are matched, i.e., for every vertex v, there is an edgee ∈M such that v ∈ e.

Exercise 4 Show that a graph has a perfect matching only if |V | is even.Give a connected graph with |V | even but no perfect matching.

Show that, for any matching M , |M | ≤ b |V |2 c.

A matching M in G is maximum if there are no other matching M ′ of G with |M ′| > |M |.Let µ(G) = |M | be the size of a maximum matching M in G. A matching M in G is maximalif there is no edge e ∈ E such that M ∪ e is a matching.

Exercise 5 Show that every maximum matching is maximal.Give examples of maximal matchings that are not maximum.

7

Page 8: Lecture on Graphs and Algorithms (Master 1)Lecture on Graphs and Algorithms (Master 1) Nicolas Nisse Abstract These are lecture notes of the course I gave, at Master 1 level. The main

Algorithm 4 Algorithm for Maximal Matching

Require: A graph G = (V,E).Ensure: A maximAL matching M of G.

1: G′ ← G and M ← ∅.2: while E(G′) 6= ∅ do3: Let e = u, v ∈ E(G′) // so, e is any (arbitrary) edge of G′

4: M ←M ∪ e and G′ ← G′[V (G′) \ u, v].5: end while6: return M .

Exercise 6 Prove that above algorithm computes a maximal matching in time O(|E|).

Proof. Three things to be proved: M is a matching, M is maximal, and the time-complexity.

Now, we focus on computing maximUM matchings in graphs. Let G = (V,E) be a graphand M ⊆ E be a matching in G. A vertex v ∈ V is covered by M if there is e ∈M , v ∈ e (i.e.,if v “touches” one edge of the matching). Let k ≥ 2. A path P = (v1, · · · , vk) is M -alternatingif, for any two consecutive edges ei−1 = vi−1, vi and ei = vi, vi+1 (1 < i < k), exactly oneof ei−1 and ei is in M . The path P is M -augmenting if P is alternating and v1 and vk are notcovered by M . Note that, in that case, v2, · · · , vk−1 are all covered by M and k is even.

Theorem 3 (Berge 1957) Let G = (V,E) be a graph and M ⊆ E be a matching in G. M ismaximum matching if and only if there are no M -augmenting paths.

Proof. First, let us assume that there is an M -augmenting path P . Show that M ′ = (M \E(P )) ∪ (E(P ) \M) (“switch” the edges in P ) is a matching and that |M ′| = |M |+ 1 and so,M is not maximum. For this purpose, first show that M ′ is a matching. Then, show that Phas odd length, i.e., 2k + 1 edges, and that k edges of P are in M and k + 1 are not in M .Conclude.

Now, assume that there are no M -augmenting paths. Recall that the symmetric differenceA∆B between two sets A and B equals (A ∪ B) \ (A ∩ B) = (A \ B) ∪ (B \ A). Let M∗ be amaximum matching in G and let X = G[M∆M∗]. So, X is the subgraph of G induced by theedges that are in M or M∗ but not in both.

Show that every vertex has degree at most two (in X) in any connected component of X.Deduce that the connected components of the graph X consist of paths and cycles (we say thatX is the disjoint union of paths and cycles).

So the connected components of X consist of cycles C1, · · · , Ck and paths P1, · · · , P`.Show that, for every i ≤ k, Ci has even size. Deduce that |E(Ci) ∩M | = |E(Ci) ∩M∗|.Let j ≤ `. Show that, because there are no M -augmenting path, |E(Pj) ∩M∗| ≤ |E(Pj) ∩M |.

Therefore, |M∗| = |M ∩M∗|+k∑i=1|E(Ci)∩M∗|+

∑j=1|E(Pj)∩M∗| ≤ |M ∩M∗|+

k∑i=1|E(Ci)∩

M | +∑j=1|E(Pj) ∩M | = |M |. So |M∗| ≤ |M | and M is a maximum matching (since M∗ is

maximum).

Theorem 3 suggests (actually proves) that, to compute a maximum matching in a graph, itis sufficient to follow the following greedy algorithm. The key point is that the order in whichaugmenting paths are considered is not relevant! (see [Bensmail et al.’17] for different behavior).

8

Page 9: Lecture on Graphs and Algorithms (Master 1)Lecture on Graphs and Algorithms (Master 1) Nicolas Nisse Abstract These are lecture notes of the course I gave, at Master 1 level. The main

Algorithm 5 Algorithm for Maximum Matching

Require: A graph G = (V,E).Ensure: A maximUM matching M of G.

1: M ← ∅.2: while there is an M -augmenting path P do3: M ← (M \ E(P )) ∪ (E(P ) \M).4: end while5: return M .

The time-complexity of previous algorithm relies on the time needed to find anM -augmentingpath (condition in the While-loop). This can actually be done in polynomial-time using the Blos-som algorithm [Edmonds 1965]. This algorithm has been improved and a maximum matchingin any graph G = (V,E) can be found in time O(

√|V ||E|) [Micali,Vazirani 1980]. Computing

matching in graphs is a basic block of many graph algorithms as we will see below.In what follows, we focus on a restricted graphs’ class, namely bipartite graphs.

2.3.1 Matchings in bipartite graphs (Hall’s theorem, Hungarian’s method)

Given a graph G = (V,E), a set of I ⊆ V is an independent set (or stable set) if, u, v /∈ Efor every u, v ∈ I (the vertices of I are pairwise not adjacent in G). A graph G = (V,E) isbipartite if V can be partitioned into two stable sets A and B.

Exercise 7 Show that any tree is bipartite.Show that a graph G is bipartite iff G has no cycle of odd size.

Proof. Show that, if there is an odd cycle in G, then it is not bipartite.Otherwise, let v be any vertex and consider a Breadth First Search (BFS6) from v. Set A

to be the vertices at even distance from v and B = V \A.

Let G = (A∪B,E) be a bipartite graph7. W.l.o.g., |A| ≤ |B|. Clearly (prove it), a maximummatching M in G is such that |M | ≤ |A|. A set S ⊆ A is saturated by a matching M of G isall vertices of S are covered by M (in which cas |M | = |A|). For any graph G = (V,E), givenS ⊆ V , let us denote N(S) = u ∈ V \ S | ∃v ∈ S, u, v ∈ E =

⋃v∈S(N(v) \ S). That is,

N(S) is the set of vertices not in S that are neighbor of some vertex in S.

Theorem 4 (Hall 1935) Given a bipartite graph G = (A∪B,E), |A| ≤ |B|, there is matchingsaturating A iff, for all S ⊆ A, |S| ≥ |N(S)|.

Proof. If there is S ⊆ A such that |S| > |N(S)| then no matching can saturates S. The reverseimplication can be proved by induction on |A|. Algorithm 6 is a constructive proof.

Prove the correctness of this algorithm (In particular, prove that, in the last Else case,|X| = |N(X)|+ 1).

Note that above algorithm, known as the Hungarian method [Kuhn 1955], can be used to findaugmenting paths in polynomial-time in bipartite graphs (just try every uncovered vertex asstarting point), and so it allows to compute a maximum matching in bipartite graphs.Understanding why this algorithm requires the graph to be bipartite would be an instructiveexercise.

6Please see [3] or [5] if you don’t know what a BFS is.7Implicitly (or say, by notation), A and B are stable sets.

9

Page 10: Lecture on Graphs and Algorithms (Master 1)Lecture on Graphs and Algorithms (Master 1) Nicolas Nisse Abstract These are lecture notes of the course I gave, at Master 1 level. The main

Algorithm 6 : Hungarian method [Kuhn 1955]

Require: A bipartite graph G = (A ∪B,E).Ensure: A matching M saturating A or a set S ⊆ A such that |S| > |N(S)|.

1: M ← ∅.2: while A is not saturated by M do3: Let a0 ∈ A be any vertex not covered by M . Set X = a0.4: Let Continue = True.5: while N(X) saturated by M and Continue do6: Y ← a0 ∪ a | ∃b ∈ N(X), a, b ∈M.7: if X ⊂ Y then8: X ← Y9: else

10: Continue = False.11: end if12: end while13: if ∃b0 ∈ N(X) not covered by M then14: Let P be an M -augmenting path between a0 and b0;15: M ← (M \ E(P )) ∪ (E(P ) \M).16: else17: return X18: end if19: end while20: return M .

2.3.2 Vertex Cover in graphs (Konig’s theorem and 2-approximation)

On the “practical” point of view, consider a city (buildings are vertices that are linked withstreets/edges). We aim at placing, say, as few as possible (because it is expansive) fire-stationsin buildings so that each building it adjacent to at least one fire-station.

This problem is modeled as follows. Given a graph G = (V,E), a set K ⊆ V is a vertexcover if K ∩ e 6= ∅ for every e ∈ E. Let vc(G) be the smallest size of a vertex cover in G. Theproblem of computing a minimum vertex cover in a graph is NP -hard in general graphs [7].

When you are facing an NP -hard problem (or, even, any problem), you must have thereflex to think to any “naive” algorithm to solve it (e.g., trying all feasible solutions and keepa best one). Precisely, imagine any feasible solution (e.g., prove that V is a vertex cover for anygraph G = (V,E)) and try to improve it.

Algorithm 7 Naive Algorithm for Minimum Vertex Cover

Require: A graph G = (V,E).Ensure: A minimum Vertex Cover of G.

1: K ← V .2: for every S ⊆ V do3: if S is a vertex cover of G and |S| < |K| then4: K ← S.5: end if6: end for7: return K

In the above algorithm, there are 2|V | iterations of the For-loop (number of subsets of V ),

10

Page 11: Lecture on Graphs and Algorithms (Master 1)Lecture on Graphs and Algorithms (Master 1) Nicolas Nisse Abstract These are lecture notes of the course I gave, at Master 1 level. The main

and each iteration requires to check if a set of vertices is a vertex cover (check if all edges aretouched), i.e., each iteration requires time O(|E|). Overall, for any G = (V,E), the problem ofcomputing vc(G) can be solved in time O(|E| · 2|V |).

Again, the goal of this lecture is to learn how/when to solve such a problem (that, unlessP = NP , cannot be solved in polynomial-time) in more efficient ways...

Now, we show that the Min. Vertex Cover problem is “easy” (can be solved in polynomial-time) in bipartite graphs. Then we show that finding a vertex cover that is “not too large” isnot difficult in any graph.

Lemma 1 Let K be any vertex cover and M be any matching of any graph G. Then |M | ≤ |K|.

Proof. For every edge e ∈ M , K ∩ e 6= ∅ by definition of a vertex cover. Moreover, for everyv ∈ K, there is at most one edge e ∈ M such that v ∈ e (by definition of a matching). So|M | ≤ |K| (each edge of M is touched by at least one vertex of K and each vertex of K touchesat most one edge of M).

Theorem 5 (Konig-Egervary 1931) For any bipartite graph G = (A ∪ B,E), the size of aminimum vertex cover vc(G) equals the size of a maximum matching µ(G).

Proof. The fact that µ(G) ≤ vc(G) follows from Lemma 1.Let M be a maximum matching of G, i.e., M is a matching of G and |M | = µ(G). If A

is saturated by M then |M | = |A| and, because G is bipartite, A is a vertex cover and theresult follows. Assume A is not saturated by M and let U ⊆ A be the uncovered vertices inA. Let X be the set of vertices linked to some vertex in U by a M -alternating path. LetXA = X ∩ A and XB = X ∩ B. Note that XB is saturated (since otherwise, there is a M -augmenting path contradicting that M is maximum by Th. 3). Moreover, XA = N(XB). Provethat Y = XB ∪ (A \XA) is a vertex cover of size |M | (take any edge e ∈ E and show that atleast one of its ends is in Y and prove that |Y | = |M |). So, vc(G) ≤ |Y | = |M | = µ(G). Note

that the proof of Theorem 5 is constructive: it allows to compute, from a maximum matchingin a bipartite graph, a minimum vertex cover in polynomial-time.

Theorem 6 Let M be any maximal matching of a graph G. Then, |M | ≤ vc(G) ≤ 2|M |.

Proof. The left inequality follows from Lemma 1.Let M be a maximal matching. Then Y =

⋃u,v∈Mu, v is a vertex cover. Indeed, if not,

there is f = x, y ∈ E such that Y ∩ x, y = ∅, and so M ∪ f is a matching, contradictingthat M is maximal. Hence, vc(G) ≤ |Y | = 2|M |.

Recap. on Min. Vertex Cover. Let us consider the problem that takes a graph G = (V,E)as input and aims at computing a set K ⊆ V , which is a vertex cover of minimum size in G.As mentioned above the corresponding decision problem is NP -complete in general graphs andcan be (naively) solved in time O(|E| · 2|V |). The goal of this lecture is to explain how/whenwe can improve this time-complexity. In the introduction, we mentioned four possible ways togo through the “P vs. NP barrier”. In the current subsection, we gave two different answersin the specific case of the Min. Vertex Cover Problem (MVCP):

Restrict inputs: By Th. 5 and algorithm of [Micali,Vazirani 1980], the MVCP can be solvedin time O(

√|V ||E|) in bipartite graphs, i.e., MVCP is in P when restricted to bipartite

graphs!!

11

Page 12: Lecture on Graphs and Algorithms (Master 1)Lecture on Graphs and Algorithms (Master 1) Nicolas Nisse Abstract These are lecture notes of the course I gave, at Master 1 level. The main

First Approximation Algorithm: Consider the following algorithm: compute M a maximalmatching of G (can be done in time O(|E|) by Alg. Maximal Matching) and returnV (M) = v | ∃e ∈ M, v ∈ M. By the proof of Th. 6, V (M) is a vertex cover ofG. Moreover, |V (M)| = 2 · |M | ≤ 2 · vc(G) (because |M | ≤ vc(G) by Th. 6). So, inpolynomial-time O(|E|), it is possible to compute a vertex cover X of any graph G thatis “not too bad” (|X| is at most twice the size of a minimum vertex cover).

Exercise 8 Give an example of graph for which the algorithm of previous paragraph gives avertex cover of size twice the optimal.

Note that last proposition relies on the following facts. We are able to compute in polynomial-time some feasible solution (here M) and to bound on both sides (lower and upper bound) thesize of any optimal solution in the size of M !!

Roughly, these are the key points of approximation algorithms as we formalize them in nextsection.

Part II

Approximation Algorithms [8]

3 Introduction to Approximation Algorithms: Load balancing

In this section, we formally define the notion of approximation algorithm (efficient algorithmthat computes a “not too bad” solution) and exemplify this notion via the Load Balancingproblem. For this problem we design and analyze two approximation algorithms, the secondalgorithm improving the first one.

3.1 Definition of an Approximation Algorithm

The following definition is not really formal since I do not want to give the formal definition ofan optimization problem here. I think/hope this will be sufficient for our purpose.

Let us consider an optimization problem Π and let w be the function evaluating the quality(or cost) of a solution. Let k ≥ 1. An algorithm A is a k-approximation for Π if each of thefollowing three conditions is satisfied. For any input I of Π:

• A computes an output O in polynomial-time (in the size of I);

• this output O is a valid solution for I, i.e., satisfies the constraints defined by Π, and

• – if Π is a minimization problem (aims at finding a valid solution with minimum cost),then w(O) ≤ k·w(O∗) where O∗ is an optimal (i.e., with minimum cost) valid solutionfor I.

– if Π is a maximization problem (aims at finding a valid solution with maximum cost),then w(O∗) ≤ k · w(O) where O∗ is an optimal (i.e., with maximum cost) validsolution for I.

For instance, if Π is the minimum vertex cover studied in previous section, the goal is, givena graph G = (V,E), to compute a set K ⊆ V with the constraint that it is a vertex cover (i.e.,every edge is touched by some vertex in K), and the cost function is the size |K| of the set.

12

Page 13: Lecture on Graphs and Algorithms (Master 1)Lecture on Graphs and Algorithms (Master 1) Nicolas Nisse Abstract These are lecture notes of the course I gave, at Master 1 level. The main

Exercise 9 Show that the algorithm that consists in computing a maximal matching M in Gand returning V (M) is a 2-approximation for the minimum vertex cover problem.

Remark. In previous definition, we have assumed that k is a constant. This definition canbe generalized by considering k as a function f of the size of the input. For instance, a f(n)-approximation is an algorithm that, given an input of size n, computes in polynomial-time avalid solution of cost at most f(n) times the cost of an optimal solution for a minimizationproblem (resp., of cost at least 1

f(n) times the cost of an optimal solution for a maximization

problem).

3.2 The Load Balancing Problem

For once, let us not speak about graphs...Let us consider a set of m ∈ N identical processors, and a set of n ∈ N jobs described

by the n-tuple (t1, · · · , tn) where ti is the time required by a processor to execute job i, forevery 1 ≤ i ≤ n. Each processor can treat only one job at a time. Moreover, we assume thateach job is unbreakable, i.e., it cannot be shared between several processors. The goal of theLoad Balancing Problem is to assign each job to one processor in order to minimize the overallcompletion time.

More formally, the goal of the Load Balancing problem is to compute a partition S =A1, · · · , Am of the jobs, i.e.,

⋃1≤i≤m

Ai = 1, · · · , n and Ai ∩ Aj = ∅ for every 1 ≤ i < j ≤ m

(this corresponds to an assignment of the jobs to the processors. Note that any Ai may be∅) minimizing max

1≤i≤m

∑j∈Ai

tj . Given an assignment S = A1, · · · , Am, the load Li(S) of the

processor i (1 ≤ i ≤ m) is∑j∈Ai

tj and max1≤i≤m

Li(S) is called the makespan of S. So the Load

Balancing problem consists in finding an assignment minimizing the makespan.

Load Balancing Problem (LBP):

Input: m ∈ N and (t1, · · · , tn) ∈ (R+)n.

Output: A partition A1, · · · , Am of 1, · · · , n such that max1≤i≤m

∑j∈Ai

tj is minimum.

The LBP is a classical NP -complete problem [7].As usual, let us first think to what could be a (naive) algorithm: try all possibilities!! Each

of the n jobs can be assigned to any of the m processors, which give mn possibilities :(Hence, we aim at designing approximation algorithms for solving it. An approximation

algorithm requires to be able to evaluate the quality of the solution it returns with respect tothe quality OPT of an optimal solution. Since, in general, we don’t know the cost of an optimalsolution, it is important to have reliable lower (in case of minimization problems) bounds on thecost of an optimal solution (resp., upper bound for maximization problems). Indeed, considera minimization problem (the case of a maximization problem is similar, prove it). If we know alower bound LB ≤ OPT of the cost of an optimal solution and that we can relate the cost c ofany solution computed by our algorithm to LB (e.g., say c ≤ k · LB for some constant k), thiswill be an indirect way to relate c and OPT : LB ≤ OPT ≤ c ≤ k · LB ≤ k ·OPT .

3.2.1 Greedy 2-Approximation (least loaded processor)

For the LBP, there are two easy lower bounds:

13

Page 14: Lecture on Graphs and Algorithms (Master 1)Lecture on Graphs and Algorithms (Master 1) Nicolas Nisse Abstract These are lecture notes of the course I gave, at Master 1 level. The main

Lemma 2 Let (m, (t1, · · · , tn)) be an instance of the LBP and let OPT be the minimummakespan over all assignments. Then max

1≤i≤nti ≤ OPT and 1

m

∑1≤i≤n

ti ≤ OPT .

Proof. The first statement is obvious. The 2nd statement follows the pigeonhole principle.

Exercise 10 Prove that, if n ≤ m, an optimal solution is to assign each job to exactly oneprocessor, and that max

1≤i≤nti = OPT .

Hence, let us assume that n > m. Let us consider the intuitive simple greedy algorithm8.Here, let us assign the jobs sequentially (in any order) to a least loaded processor.

Algorithm 8 : 2-Approximation for Load Balancing Problem

Require: n > m ∈ N and (t1, · · · , tn) ∈ (R+)n.Ensure: A partition A1, · · · , Am of 1, · · · , n.

1: A1, · · · , Am ← ∅, · · · , ∅.2: for i = 1 to n do3: A1 ← A1 ∪ i.4: Reorder the Ai’s such that

∑j∈A1

tj ≤∑j∈A2

tj ≤ · · · ≤∑

j∈Am

tj .

5: end for6: return A1, · · · , Am.

Theorem 7 Algorithm 8 is a 2-approximation for the LBP, with time-complexity O(n logm).

Proof. There are 3 properties to be proved! First, it returns a valid solution, i.e., here thecomputed solution A1, · · · , Am is a partition of 1, · · · , n. This is obvious (I hope?).

Second, it has polynomial-time complexity. Indeed, there are n iterations of the For-loop,and each of them requires to re-sort an already sorted list of m elements where only one haschanged, which takes O(logm) time per iteration (see, e.g., [3]).

The third property, i.e., that the makespan L = max1≤i≤m

∑j∈Ai

tj of the computed partition

A1, · · · , Am is at most twice the optimal makespan OPT , is the most “difficult” to prove.For any i ≤ m, let Li =

∑j∈Ai

tj .

Let x ≤ m be such that L = Lx = max1≤i≤m

Li (i.e., Processor x is one of the most loaded in

the computed solution). Note that OPT ≤ L.Let j ≤ n be the last job assigned to Ax, i.e., j is the maximum integer in Ax. Note that

tj ≤ OPT by the first statement of Lemma 2.For every 1 ≤ y ≤ m, let L′i be the load of Processor i when tj is assigned to Px (i.e., after

iteration j − 1 of the For-loop). Then, Lx − tj ≤ L′i for every i ≤ m (indeed, it is obviousfor i = x, and if there is y ∈ 1, · · · ,m \ x with Lx − tj > L′y, the job j would have beenassigned to Processor y by the definition of Algorithm 8). Since, for every 1 ≤ i ≤ m, the loadof Processor i is not decreasing during the algorithm, this implies that Lx − tj ≤ Li for everyi ≤ m.

Therefore, m(Lx− tj) ≤∑

1≤i≤mLi =

∑1≤i≤n

ti. Hence, Lx− tj ≤ 1m

∑1≤i≤n

ti ≤ OPT where the

last inequality is given by the second statement of Lemma 2.

8Roughly, an algorithm is greedy if each of its steps is guided by a simple local (i.e., depending on the currentstate) rule.

14

Page 15: Lecture on Graphs and Algorithms (Master 1)Lecture on Graphs and Algorithms (Master 1) Nicolas Nisse Abstract These are lecture notes of the course I gave, at Master 1 level. The main

Hence, by previous paragraphs, we have tj ≤ OPT and Lx − tj ≤ OPT .To conclude, L = Lx = (Lx − tj) + tj ≤ OPT +OPT = 2 ·OPT .

Note that, sometimes, the algorithm is better than we can expect from its analysis. Forinstance, previous theorem proves that Algorithm 8 is a 2-approximation for the LBP. The nextquestion is whether Algorithm 8 is a c-approximation for the LBP for some c < 2. Note thatthe latter is not true if we can find an instance for which Algorithm 8 computes a solution ofcost exactly twice the optimal.

Exercise 11 Let m ∈ N and n = (m−1)m+1. Apply Algorithm 8 to the input (m, (t1, · · · , tn))where t1 = · · · ,= tn−1 = 1 and tn = m. Conclusion (let m tend to ∞)?

Hence, to expect a c-Approximation for the LBP with c < 2, we need another algorithm.

3.2.2 Greedy 32-Approximation (least loaded processor and ordered tasks)

Algorithm 9 : 32 -Approximation for Load Balancing Problem

Require: n > m ∈ N and (t1, · · · , tn) ∈ (R+)n.Ensure: A partition A1, · · · , Am of 1, · · · , n.

1: Order the jobs in non decreasing order of their completion time, i.e. t1 ≥ · · · ≥ tn.2: A1, · · · , Am ← ∅, · · · , ∅.3: for i = 1 to n do4: A1 ← A1 ∪ i.5: Reorder the Ai’s such that

∑j∈A1

tj ≤∑j∈A2

tj ≤ · · · ≤∑

j∈Am

tj .

6: end for7: return A1, · · · , Am.

Note that Algorithm 9 only differs from Algorithm 8 by its first step that consists in orderingthe jobs by non-decreasing completion time. However, it offers us the opportunity to use a newlower bound (proved by pigeonhole principle).

Lemma 3 Let n > m, (m, (t1, · · · , tn)) be an instance of the LBP with t1 ≥ · · · ≥ tn and letOPT be the minimum makespan over all assignments. Then OPT ≥ 2 · tm+1.

Theorem 8 Algorithm 9 is a 32 -approximation for the LBP, with time-complexity O(n log n).

Proof. Again, Algorithm 9 computes a valid solution (a partition) A1, · · · , Am. Moreover,the bottleneck for the time-complexity is the first step that takes time O(n log n). It onlyremains to prove the approximation ratio.

For any i ≤ m, let Li =∑j∈Ai

tj and let x ≤ m be such that L = Lx = max1≤i≤m

Li (i.e.,

Processor x is one of the most loaded in the computed solution). Note that OPT ≤ L.Let j ≤ n be the last job assigned to Ax, i.e., j is the maximum integer in Ax. Then,

j ≥ m + 1 and 2 · tj ≤ OPT by Lemma 3 and because tj ≤ tm+1. As in the proof of previoustheorem, Lx − tj ≤ OPT . Hence, Lx = (Lx − tj) + tj ≤ OPT +OPT/2 = 3

2 ·OPT .

15

Page 16: Lecture on Graphs and Algorithms (Master 1)Lecture on Graphs and Algorithms (Master 1) Nicolas Nisse Abstract These are lecture notes of the course I gave, at Master 1 level. The main

4 Traveling Salesman Problem (TSP)

4.1 Different variants and exact dynamic programming algorithm

A salesman has to visit several cities but aims at minimizing the length (or cost) of his journey.The TSP aims at computing a best possible route for the salesman.

More formally, let Kn be the complete graph (or clique) with n vertices, i.e., the graph withall possible edges between the n vertices. Recall that the weight of a subgraph H is

∑e∈E(H)

w(e).

Given the clique Kn with edge-weight w : E(Kn)→ R+, the Traveling Salesman Problem (TSP)aims at computing a Hamiltonian cycle of minimum weight in (Kn, w).

Note that the problem is restricted to complete graphs to ensure that there exists a Hamil-tonian cycle. However, the TSP is equivalent to the problem of computing a minimum-weightwalk9 passing through all vertices and going back to the initial vertex in any graph. Indeed,let G = (V,E) be a graph with edge-weight ` : E → R+. The distance between 2 verticesu, v ∈ V , denoted by distG(u, v), is the minimum weight of a path from u to v in (G, `). Letw : V × V → R+ that assigned to every pair (u, v) of vertices the weight w(u, v) = distG(u, v).

Exercise 12 Show that there exists a Hamiltonian cycle in (Kn, w) of weight ≤ k ∈ R+ if andonly if there exists a walk passing through all vertices and going back to the initial vertex, in G,with weight ≤ k.

Given (Kn, w) and k ∈ R+, the problem of deciding whether there exists a Hamiltonian cycleof weight at most k is NP-complete [7]. The algorithm proposed in Section 2.1 to decide if agraph has a Hamiltonian cycle can be directly adapted to solve the TSP in time O(n ·n!). Here,we show how to improve the time complexity by presenting a dynamic programming algorithm.

Let v1 ∈ V (Kn) and let S ⊆ V (Kn) \ v1 be a non-empty set of vertices and v ∈ S. LetOPT [S, v] denote the minimum weight of a path that starts in v1 and visits exactly all verticesin S, ending in v. Clearly, for every v 6= v1, OPT [v, v] = w(v1, v).

Lemma 4 Let S ⊆ V (Kn) \ v1 with |S| ≥ 2 and let v ∈ S.

OPT [S, v] = minu∈S\v

OPT [S \ v, u] + w(u, v).

Proof. The proof is by double inequalities.First, let P be a path from v1 to v, with V (P ) = S ∪ v1 and with weight OPT [S, v]. Let

x be neighbor of v in P and let P ′ be the subpath of P from v1 to x. Then, OPT [S, v] =w(P ′) + w(x, v) ≥ OPT [S \ v, x] + w(x, v) ≥ minu∈S\vOPT [S \ v, u] + w(u, v).

Conversely, let x ∈ S \ v1 be such that OPT [S \ v, x] + w(x, v) is minimum. LetP ′ be a path from v1 to x, with V (P ) = (S \ v) ∪ v1 and with weight OPT [S \ v, x].Let P be the path from v1 to v obtained from P ′ by adding to it the edge x, v. Then,minu∈S\vOPT [S \ v, u] + w(u, v) = OPT [S \ v, x] + w(x, v) = w(P ) ≥ OPT [S, v].

Theorem 9 (Bellman-Held-Karp 1962) Algorithm 10 computes the minimum weight of aHamiltonian cycle (and can be easily adapted to compute a minimum-weight Hamiltonian cycle)in time O(n2 · 2n).

9The weight of a walk (v1, · · · , vk) is∑

1≤i<k

w(vi, vi+1), i.e., the multiplicity of edges is taken into account.

16

Page 17: Lecture on Graphs and Algorithms (Master 1)Lecture on Graphs and Algorithms (Master 1) Nicolas Nisse Abstract These are lecture notes of the course I gave, at Master 1 level. The main

Algorithm 10 : Dynamic Programming for TSP [Bellman-Held-Karp 1962]

Require: Complete graph Kn = (V,E) with w : E → R+.Ensure: The minimum weight of a Hamiltonian cycle.

1: Let v1 ∈ V .2: for v ∈ V \ v1 do3: OPT [v, v] = w(v1, v).4: end for5: for S ⊆ V \ v1 with |S| ≥ 2 in non decreasing size order do6: for v ∈ V \ v1 do7: OPT [S, v] = minu∈S\vOPT [S \ v, u] + w(u, v).8: end for9: end for

10: return minv∈V \v1OPT [V \ v1, v] + w(v, v1).

Proof. The time complexity comes from the fact that there are O(2n) sets S to be considered.For each set S, and for each of the O(n) vertices in V \v1, the algorithm must find a minimumvalue among O(n) values, so each iteration of the main For-loop takes time O(n2).

The correctness follows the fact that, after the last “EndFor”, the values OPT [V \ v1, v]are known for every v ∈ V \v1 (by Lemma 4). To conclude, let C∗ be an optimal Hamiltoniancycle and let OPT be its weight. The proof is by double inequalities.

Let x be a neighbor of v1 in C∗ and let P be the path obtained from C∗ by removing the edgev1, x. Then, OPT = w(P ) +w(v1, x) ≥ OPT [V \ v1, x] +w(x, v1) ≥ minv∈V \v1OPT [V \v1, v] + w(v, v1). Finally, let x ∈ V \ v1 minimizing OPT [V \ v1, x] + w(x, v1) and letP be a spanning path from v1 to x with weight OPT [V \ v1, x]. Then adding the edgex, v1 to P leads to a Hamiltonian cycle C and so, minv∈V \v1OPT [V \ v1, v] +w(v, v1) =OPT [V \ v1, x] + w(x, v1) = w(C) ≥ OPT .

No algorithm for solving TSP in time O(cn) is known for any c < 2. Moreover,

Theorem 10 If P 6= NP , there is no c-approximation algorithm for solving TSP, for anyconstant c ≥ 1.

So the TSP problem is difficult and it is even difficult to approximate it. To overcomethis difficulty, there may be several options. Here, we discuss two of them: simplifying theproblem and/or restricting the instances. To simplify the problem, we may allow repetitionsof vertices and edges. So, let TSP r be the problem that, given a weighted Kn, must computea closed10 walk, passing through all vertices, and with minimum weight. On the other hand,we may restrict the instances of the TSP. Since considering a complete graph is importantbecause it ensures the existence of a Hamiltonian cycle, let us restrict the weight function. Aweight function w : V × V → R+ satisfies the triangular inequality if, for every a, b, c ∈ V ,w(a, b) ≤ w(a, c) + w(c, b). Let TSPti be the problem that, given a weighted (Kn, w) wherew satisfies the triangular inequality, must compute a Hamiltonian cycle with minimum weight.Finally, let TSP rti be the problem that, given a weighted (Kn, w) where w satisfies the triangularinequality, must compute a closed walk, passing through all vertices, and with minimum weight.

Lemma 5 Any c-approximation algorithm for one problem in TSP r, TSPti, TSP rti can beturned into a c-approximation algorithm for any problem in TSP r, TSPti, TSP rti.

10“Closed” means that the starting and final vertices are the same.

17

Page 18: Lecture on Graphs and Algorithms (Master 1)Lecture on Graphs and Algorithms (Master 1) Nicolas Nisse Abstract These are lecture notes of the course I gave, at Master 1 level. The main

Proof. Any solution for TSPti is a solution for TSP rti (with same weight). Similarly, anysolution for TSP r is a solution for TSP rti (with same weight).

Let W = (v1, · · · , vk) be a solution for TSP rti. If no vertex is repeated, then W is a solutionof TSPti. Otherwise, let us assume that there are 1 ≤ i < j < k such that vi = vj , thenW ′ = (v1, · · · , vj−1, vj+1, · · · , vk) is a solution and the weight of W ′ is not larger than theweight of W by the triangular inequality. Repeating this process sequentially until no vertex isrepeated leads to a solution of TSPti (without increasing the weight).

Finally, let (Kn = (V,E), w) be an instance of TSP r. Let distKn : E → R+ be thedistance function with respect to w. Prove that distKn satisfies the triangular inequality. Then,(Kn, distKn) is an instance of TSPti. Following Exercise 12, any solution of (Kn, distKn) forTSPti leads to a solution (with same weight) of (Kn, w) for TSP r.

Prove that above arguments allow to prove the lemma.

4.2 2-Approximation (using minimum spanning tree)

Let us now show that these problems (TSP r, TSPti, TSPrti) admit “good” approximation algo-

rithms. Precisely, let us first consider the problem TSP r. Since repetitions of edges/verticesare allowed, we may consider any connected graph (rather than complete graphs) since closedwalk passing through every vertex always exists in any connected graph. Recall the notion ofDepth First Search (DFS) of a tree [3].

As usual, the design (and analysis) of an approximation algorithm for solving some opti-mization problem Π requires some lower bound (if possible, that can be computed in polynomialtime) on the quality of an optimal solution of Π.

Lemma 6 Let G = (V,E) be a connected graph and w : E → R+. Let w∗ be the minimumweight of a closed walk passing through all vertices in V . Let t∗ be the minimum weight of aspanning tree in G. Then, t∗ ≤ w∗.

Proof. Let W be any closed walk passing through all vertices in V and with minimum weightw(W ) = w∗. Then, E(W ) induces a connected spanning subgraph H of G with weight w(H) ≤w(W ) (the difference between w(H) and w(W ) is that, in w(H), each edge is counted only once).Let T be any minimum spanning tree of G. By Exercise 3, the weight t∗ = w(T ) of T is at mostthe weight of any connected spanning subgraph. Hence, t∗ = w(T ) ≤ w(H) ≤ w(W ) = w∗.

Algorithm 11 : 2-approximation for TSP r

Require: A connected graph G = (V,E) with w : E → R+.Ensure: A closed walk passing through every vertex in V .

1: Let T be a minimum spanning tree of G.2: return the closed walk defined by any DFS-traversal of T .

Theorem 11 Algorithm 11 is a 2-approximation algorithm for the problem TSP r.

Proof. The fact that Algorithm 11 returns a valid solution is trivial. Its time-complexityfollows from the one of the problem of computing a minimum spanning tree which can be donein polynomial-time (Th. 2). Finally, the weight of the computed walk W is twice the minimumweight t∗ of the computed spanning tree T (because W follows a DFS of T , each edge of T iscrossed exactly twice in W ). Hence, w(W ) = 2t∗ ≤ 2w∗ where w∗ is the weight of an optimalclosed spanning walk (by Lemma 6).

18

Page 19: Lecture on Graphs and Algorithms (Master 1)Lecture on Graphs and Algorithms (Master 1) Nicolas Nisse Abstract These are lecture notes of the course I gave, at Master 1 level. The main

4.3 32-Approximation (Christofides’algorithm)

Let us conclude this section by an even better approximation algorithm. To simplify the pre-sentation, let us consider the TSPit. The next approximation algorithm relies on a new lowerbound.

Lemma 7 Let Kn with w : E → R+ satisfying the triangular inequality, and let w∗ be theminimum weight of a Hamiltonian cycle. Let V ′ ⊆ V (Kn) with |V ′| even. Finally, let M be aminimum weight perfect matching of V ′. Then, w(M) ≤ w∗/2.

Proof. Let C be an optimal Hamiltonian cycle of Kn and let C ′ be the cycle spanning V ′

obtained by short-cutting C. By triangular inequality, w(C ′) ≤ w(C) = w∗. Moreover, E(C ′)can be partitioned into two perfect matchings M1 and M2 of V ′. Since w(C ′) = w(M1)+w(M2),w.l.o.g., w(M1) ≤ w(C ′)/2. Finally, w(M) ≤ w(M1) ≤ w(C ′)/2 ≤ w(C)/2 = w∗/2.

Algorithm 12 : 3/2-approximation for TSPti [Christofides 1976]

Require: A complete graph Kn = (V,E) with w : E → R+ satisfying the triangular inequality.Ensure: A Hamiltonian cycle.

1: Let T ∗ be a minimum spanning tree of G.2: Let O be the set of vertices with odd degree in T ∗.3: Let M be a perfect matching, with minimum weight, between the vertices in O.4: Let H be the graph induced by E(T ∗) ∪M (possibly, H has parallel edges) and C be an

eulerian cycle in H.5: return the Hamiltonian cycle obtained by considering the vertices in the order they are

met for the first time in C.

Theorem 12 (Christofides 1976) Algorithm 12 is a 3/2-approximation algorithm for theproblem TSPti.

Proof. Note that, by Proposition 1, O has even size and then, it is easy to see that M is welldefined (because |O| is even and we are in a clique) and can be computed in polynomial time. Byconstruction, every vertex has even degree in H and so C is well defined and can be computed inpolynomial time (Th. 1). Finally, the Hamiltonian cycle returned by the algorithm has weightat most w(C) by the triangular inequality. Hence, Algorithm 12 computes, in polynomial time,a Hamiltonian cycle with weight at most w(C) = w(T ∗) + w(M). The result follows fromLemmas 6 and 7.

5 Set Cover

To continue with approximation algorithms, let us consider that a new problem that is not(directly) related to graphs.

The Set Cover problem takes as inputs a ground set (a universe) U = e1, · · · , en ofelements, a set S = S1, · · · , Sm ⊆ 2U of subsets of elements and k ∈ N. The goal is to decideif there exists a set K ⊆ 1, · · · ,m such that

⋃j∈K

Sj = U and |K| ≤ k. In “optimization”

words, the Set Cover problem aims at computing a minimum number of sets in S covering allelements in U .

As an example, consider a set of persons, each one speaking only its own language (English,French, Spanish...) and a set of translators, each ones speaking several langages (the first

19

Page 20: Lecture on Graphs and Algorithms (Master 1)Lecture on Graphs and Algorithms (Master 1) Nicolas Nisse Abstract These are lecture notes of the course I gave, at Master 1 level. The main

translator knows French, Chinese and Russian, the second one knows French and Spanish...).What is the minimum number of translators required to be able to communicate with allpersons?

Exercise 13 Formalize the above paragraph in terms of Set Cover problem (define U and S).Invent another application of the Set Cover problem.

Without surprise (given the topic of this course), the Set Cover problem is NP-complete [7].

5.1 Relationship with Graphs: Dominating Set and Vertex Cover

Before trying to solve the Set Cover problem, let us discuss its relationship with graphs. Thissubsection aims at getting a better understanding of Set Cover problem by considering it bydifferent points of view (related to graphs).

Given a graph G = (V,E), a dominating set D ⊆ V is a set of vertices such that N [D]11 = V .The minimum size of a dominating set in G is denoted by γ(G).

Exercise 14 Show that, for any graph G = (V,E), γ(G) ≤ vc(G) (recall that vc(G) is theminimum size of a vertex cover in G). That is, prove that any vertex cover is a dominating set.

Give a graph G in which γ(G) < vc(G).

The minimum Dominating Set (MDS) problem takes a graph G = (V,E) and k ∈ N asinputs, and asks whether γ(G) ≤ k. The MDS problem is actually “related” to the Set Coverproblem. Precisely, we show below that, any polynomial-time algorithm solving the MDSproblem in bipartite graphs may be used to solve the Set Cover problem in polynomial-time.

Let (U = e1, · · · , en,S = S1, · · · , Sm, k) be an instance of the Set Cover problem. Let usdefine the bipartite graph G(U,S) = (A∪B,E) as follows. Let A = U ∪ r and B = S ∪ r′.Let us add an edge between r and every vertex in B, and an edge r, r′. Then, for everyu ∈ U = A \ r and s ∈ B = S, there is an edge u, s ∈ E if and only if u ∈ s.

Lemma 8 Let k ∈ N. There exists a Set Cover of (U,S) of size ≤ k iff there exists a dominatingset of G(U,S) of size ≤ k + 1.

Proof. Let K ⊆ S be a set cover of (U,S). Then, it is easy to check that K ∪ r is adominating set in G(U,S).

Let D ⊆ V (G(U,S)) be a dominating set in G(U,S). Prove that either r or r′ belongs toD, and that, if r′ ∈ D, then (D \ r′) ∪ r is a dominating set with size no larger than |D|.Hence, we may assume that r ∈ D and r′ /∈ D. Now, if there is u ∈ D ∩ U , let s ∈ S suchthat u, s ∈ E(G(U,S)) (i.e., u ∈ s). Show that (D \ u) ∪ s is a dominating set with sizeno larger than |D|. Hence, we may assume that r ∈ D and D ⊆ S ∪ r. Finally, show thatD \ r is a set cover of (U,S).

On the other hand, Set Cover is “related” to the Vertex Cover problem. Precisely, anypolynomial-time algorithm solving the Set Cover problem can be used to solve the VertexCover problem in polynomial-time. For every graph G = (V,E) and, for every v ∈ V , letEv = uv ∈ E | u ∈ V be the set of edges adjacent to v.

Exercise 15 Let G = (V,E) be a graph. For any K ⊆ V , Ev | v ∈ K is a Set Cover of(E, Ev | v ∈ V ) if and only if K is a vertex cover of G.

11In a graph G = (V,E) and given X ⊆ V , N(X) = u ∈ V \X | ∃v ∈ X, u, v ∈ E and N [X] = N(X)∪X.

20

Page 21: Lecture on Graphs and Algorithms (Master 1)Lecture on Graphs and Algorithms (Master 1) Nicolas Nisse Abstract These are lecture notes of the course I gave, at Master 1 level. The main

Remark. The following goes beyond this course (since, I voluntary do not want to go intomore details about NP-hardness). However, let us mention that above paragraphs actuallyconsist of reductions leading to hardness proofs. If you already know what it is about, there isno need for more details, otherwise let us just state the following consequence.

Since the Set Cover problem is NP-hard and, since buildingG(U,S) can be done in polynomial-time, Lemma 8 leads to the following corollary.

Corollary 1 The Minimum Dominating Set problem is NP-hard even if the input graphs arerestricted to the class of bipartite graphs.

Similarly, since the Vertex Cover problem is NP-hard and, since building (E, Ev | v ∈ V )can be done in polynomial-time, Exercise 15 leads to the following corollary.

Corollary 2 The Set Cover problem is NP-hard even if the input (U,S) is such that everyelement of U is in at most 2 sets in S.

5.2 Greedy O(log n)-approximation

Let (U = e1, · · · , en,S = S1, · · · , Sm ⊆ 2U ) be an instance of the Set Cover problem.Moreover, we consider a cost function c : S → R+ over the sets. This section is devoted to thecomputation of a minimum-cost solution.

Exercise 16 Give a “naive” algorithm that computes a set K ⊆ 1, · · · ,m such that⋃j∈K

Sj =

U and of minimum cost in time O∗(2m)12.

Next, let us present a greedy algorithm for the Set Cover problem that, while very simple,appears to be an approximation algorithm with best asymptotic approximation ratio. Moreprecisely, the greedy algorithm sequentially adds to the set cover, while the set cover doesnot cover all elements, a new set with minimum effective cost defined as follows. Given F ⊆1, · · · ,m, XF =

⋃i∈F

Si and j ∈ 1, · · · ,m \ F such that Sj \XF 6= ∅, let the effective cost

of Sj , denoted by ceff (Sj , F ), bec(Sj)|Sj\XF | (i.e., the cost of Sj is shared among the elements that

are not covered by F ). Note that, if c(Si) = 1 for all i ≤ m, a set Sj has minimum effective costwith respect to F iff Sj is a set covering the maximum number of elements uncovered by F .

The intuition behind this algorithm can be stated as follows. At each iteration, when a newset Si is added in the solution, its effective cost is equally distributed to each element that Siallows to cover. Precisely, for every element e ∈ U , let us assume that e is covered for the firsttime when a set Si is added to the current solution K (i.e., consider the value of K before Siis added to it). Let us say that this element e receives price(e) = ceff (Si,

⋃j∈K

Sj) = c(Si)|Si\

⋃j∈K

Sj | .

Claim 1 Let K be the solution computed by Algorithm 13.Then,

∑e∈U

price(e) =∑j∈K

c(Sj).

Let us now prove the main theorem of this section.

Theorem 13 (Chvatal 1979) Algorithm 13 is a O(log n)-approximation algorithm for the SetCover problem (with n being the size of the ground-set/universe U).

12A function f(n) = O∗(g(n)) if there exists c > 0 such that f(n) = O(g(n)nc), i.e., O∗ omits polynomialfactors.

21

Page 22: Lecture on Graphs and Algorithms (Master 1)Lecture on Graphs and Algorithms (Master 1) Nicolas Nisse Abstract These are lecture notes of the course I gave, at Master 1 level. The main

Algorithm 13 : Greedy O(log n)-approximation for Set Cover. [Chvatal 1979]

Require: (U,S = S1, · · · , Sm ⊆ 2U ).Ensure: K ⊆ 1, · · · ,m such that

⋃j∈K

Sj = U .

1: Let K = ∅.2: while

⋃j∈K

Sj 6= U do

3: Let i ∈ 1, · · · ,m \K such that

• Si \⋃j∈K

Sj 6= ∅, and

• ceff (Si,⋃j∈K

Sj) = c(Si)|Si\

⋃j∈K

Sj | is minimum.

4: K ← K ∪ i.5: end while6: return K.

Proof.Algorithm 13 clearly returns a valid solution in polynomial-time. Let us focus on theapproximation ratio.

Let K = j1, · · · , jk ⊆ 1, · · · ,m be a solution returned by above algorithm. For every1 ≤ i ≤ k, let Xi =

⋃<i

Sj` be the set of elements already covered before the ith iteration of the

While-loop.Let K∗ be an optimal solution for the Set Cover problem and let OPT =

∑j∈K∗

c(Sj). For

every 1 ≤ i ≤ k, let Fi ⊆ K∗ such that, for every j ∈ Fi, Sj is needed to cover some vertex inE \Xi (i.e., for all j ∈ Fi,

⋃`∈Fi\j

S` does not cover U \Xi). By the pigeonhole principle:

Claim 2 For every 1 ≤ i ≤ k, there is j ∈ Fi such that ceff (Sj , Xi) ≤ OPTn−|Xi| .

Proof of Claim. First, let us show that the total cost∑j∈Fi

c(Sj) ≤ OPT of the sets in Fi is

distributed to the elements in U \ Xi (by considering the effective costs of these sets and theprices of elements in U \Xi as in above claim).

Precisely, let us set Sj | j ∈ Fi = S∗1 , · · · , S∗|Fi| and assume that these sets are “added” to

the optimal solution in this order. Hence, for all j ≤ |Fi|, the effective cost ceff (S∗j , Xi∪⋃`<j

S∗` ) =

c(S∗j )

|S∗j \(Xi∪⋃`<j

S∗` )|(Note that, because K∗ is an optimal solution, for every j ∈ Fi, there is at least

one element covered only by Sj , and so this effective cost is well defined) is equally distributedamong the elements in S∗j \ (Xi ∪

⋃`<j

S∗` ). Hence, the total cost∑j∈Fi

c(Sj) =∑

j≤|Fi|c(S∗j ) ≤ OPT

is distributed over the elements of U \Xi.

By the pigeonhole principle, some element must receive a price at most

∑j∈Fi

c(Sj)

|U\Xi| ≤OPT|U\Xi| .

Hence, the set S∗j , j ≤ |Fi|, associated to this element has effective cost at most OPT|U\Xi| = OPT

n−|Xi| .

Let us go back to the solution computed by Algorithm 13. Let us assume that all elementsof U are covered in the following order (e1, · · · , en).

Let j ≤ n and assume that the element ej ∈ U is covered when the set Sji (for some i ≤ k)is added to the solution. By claim above, there is t ∈ Fi such that ceff (St, Xi) ≤ OPT

n−|Xi| . By the

22

Page 23: Lecture on Graphs and Algorithms (Master 1)Lecture on Graphs and Algorithms (Master 1) Nicolas Nisse Abstract These are lecture notes of the course I gave, at Master 1 level. The main

definition of the algorithm, this implies that ceff (Sji , Xi) ≤ ceff (St, Xi) ≤ OPTn−|Xi| . Moreover,

Xi ⊆ e1, · · · , ej−1 (since ej is not covered before Sji is added and so ej , · · · , en /∈ Xi) and,therefore, |Xi| ≤ j − 1 and so, price(ej) = ceff (Sj , Xi) ≤ OPT

n−j+1 .

It follows that∑j∈K

c(Sj) =∑

1≤j≤nprice(ej) ≤

∑1≤j≤n

OPTn−j+1 = OPT ·

∑1≤j≤n

1j = O(log n)·OPT .

It can be proved that no o(log n)-approximation algorithm exists (unless P = NP ) for the SetCover problem [8]. That is, Algorithm 13 is asymptotically optimal in terms of approximationratio (as a function of n). However, if the input (U,S) is such that every element of U appearsin at most f ≥ 2 sets in S, better performances may be achieved (e.g., Vertex Cover, wheref = 2). For instance, rounding of linear programming relaxation allows the design of a O(f)-approximation (e.g., see here).

6 Knapsack and (F)PTAS

The Knapsack problem takes a set of integers S = w1, · · · , wn and an integer b as inputs.

The objective is to compute a subset T ⊆ 1, · · · , n of items such that∑i∈T

wi ≤ b and∑i∈T

wi is

maximum. That is, we want to fill our knapsack without exceeding its capacity b and puttingthe maximum total weight in it.

6.1 (Pseudo-polynomial) Exact Algorithm via dynamic programmingRecall that Dynamic Programming is a generic algorithmic method that consists in solving aproblem by combining the solutions of sub-problems.

As an example, the Simple Knapsack Problem consists in computing an optimal solutionfor an instance S = w1, · · · , wn and an integer b. Let OPT (S, b) denote such a solution. Wewill compute it using solutions for sub-problems with inputs Si = w1, · · · , wi and b′ ∈ N, forany i ≤ n and b′ < b. That is, we will compute OPT (S, b) from all solutions OPT (Si, b′) fori ≤ n and b′ < b.

Algorithm 14 Dynamic programming algorithm for Knapsack

Require: A set of integers S = w1, · · · , wn and b ∈ N.

Ensure: A subset OPT ⊆ 1, · · · , n of items such that∑i∈T

wi ≤ b

1: For any 0 ≤ i ≤ n and any 0 ≤ b′ ≤ b, let OPT [i, b′] = ∅;2: For any 0 ≤ i ≤ n and any 0 ≤ b′ ≤ b, let opt cost[i, b′] = 0;3: for i = 1 to n do4: for b′ = 1 to b do5: if maxopt cost[i− 1, b′ − wi] + wi, opt cost[i− 1, b′] = opt cost[i− 1, b′] then6: OPT [i, b′] = OPT [i− 1, b′]7: opt cost[i, b′] = opt cost[i− 1, b′]8: else9: OPT [i, b′] = OPT [i− 1, b′ − wi] ∪ i

10: opt cost[i, b′] = opt cost[i− 1, b′ − wi] + wi11: end if12: end for13: end for14: return OPT = OPT [n, b]

23

Page 24: Lecture on Graphs and Algorithms (Master 1)Lecture on Graphs and Algorithms (Master 1) Nicolas Nisse Abstract These are lecture notes of the course I gave, at Master 1 level. The main

Theorem 14 Algorithm 14 computes a optimal solution for the Knapsack problem in timeO(n · b).

Proof. Algorithm 14 consists in two imbricated loops, the first one with O(n) iterations andthe second one with O(b) iterations. “Inside” the second loop, there are a constant number ofoperations (tests, comparisons, arithmetical operations). Hence, its time-complexity is O(nb).

To prove the correctness of Algorithm 14, let us first understand the meaning of OPT (Si, b′)(i ≤ n, b′ ≤ b). The set OPT (Si, b′) is a combination (a choice/a subset) of elements in1, · · · , i that maximizes the weight of the chosen elements such that it does not exceed b′.That is OPT (Si, b′) ⊆ 1, · · · , i is such that opt(Si, b′) =

∑j∈OPT (Si,b′)

wj ≤ b′ and, for every

T ⊆ 1, · · · , i with w(T ) =∑j∈T

wj ≤ b′, then w(T ) ≤ opt(Si, b′). The key point is that,

Claim 3 For every 1 ≤ i ≤ n and b′ ≤ b, opt(Si, b′) = maxopt(Si−1, b′), wi+opt(Si−1, b′−wi).

Proof of Claim. Clearly, OPT (Si, b′) is obtained either by not taking the ith element, in whichcase a solution is OPT (Si−1, b′), or by taking the ith element (with weight wi) and adding to itOPT (Si−1, b′ − wi). Formally prove this claim by “mimicking” the proof of Theorem 4.

Then, the correctness easily follows by induction. Indeed, by Lines 1-2, OPT [0, b′] =OPT (S0, b′) = ∅ and opt cost[0, b′] = opt(S0, b′) = 0 for every b′ ≤ b (setting S0 = ∅). Then,by induction on i ≤ n, let us assume that, for every b′ ≤ b, OPT [i, b′] = OPT (Si, b′) andopt cost[i, b′] = opt(Si, b′). Then, by Lines 5-10, opt cost[i + 1, b′] = maxopt cost[i, b′], wi +opt cost[i, b′ − wi]. By the induction hypothesis, opt cost[i, b′] = opt(Si, b

′) and opt cost[i, b′ −wi] = opt(Si, b

′−wi). By the claim, opt(Si+1, b′) = maxopt(Si, b′), wi+opt(Si, b′−wi). Hence,

opt cost[i+ 1, b′] = opt(Si+1, b′) and similarly, OPT [i+ 1, b′] = OPT (Si+1, b

′).So, the algorithm returns OPT [n, b] = OPT (Sn, b) which is, by definition, an optimal solu-

tion.

Exercise 17 Explain that we may assume that maxiwi ≤ b and b ≤∑

iwi since, otherwise,the instance may be simplified.

Prove that, if maxiwi ≤ b ≤∑

iwi, Algorithm 14 proceed in polynomial-time if maxiwi ispolynomial in n but exponential if maxiwi is exponential in n.

Actually, the Knapsack Problem is an example of Weakly NP-hard (roughly, it can besolved in polynomial-time if the weights are polynomial). Typically (informally), a weaklyNP-hard problem takes a set of n integers as inputs and can be solved in time polynomial inthe number of integers (n) and in the maximum value of the integers (pseudo-polynomialalgorithm) but, if the values of the integers are exponential in the number n of integers, we donot know any polynomial-time (in n) algorithm to solve it.

6.2 Greedy 2-Approximation and PTASNote that Algorithm 15 proceeds in a greedy way: it takes one by one the possible items (in

non increasing order of their weights) and simply add them if they fit in the sack.

Theorem 15 Algorithm 15 is a 2-approximation algorithm for the Knapsack problem.

Proof. In line 3, there is a sorting of n integers (time O(n log n)), then there is a loop withn iterations with, for each iteration, a constant number of operations. Hence, the algorithm

24

Page 25: Lecture on Graphs and Algorithms (Master 1)Lecture on Graphs and Algorithms (Master 1) Nicolas Nisse Abstract These are lecture notes of the course I gave, at Master 1 level. The main

Algorithm 15 Greedy 2-approximation for Knapsack

Require: A set of integers S = w1, · · · , wn and b ∈ N.

Ensure: A subset T ⊆ 1, · · · , n of items such that∑i∈T

wi ≤ b1: T = ∅2: total weight = 03: Sort S such that w1 ≥ w2 ≥ · · · ≥ wn.4: for i = 1 to n do5: if total weight+ wi ≤ b then6: Add i to T7: Add wi to total weight8: end if9: end for

10: return T

has complexity O(n log n). Moreover, it clearly computes a valid solution. Hence, it onlyremains to prove the approximation ratio. Let OPT =

∑i∈S∗

wi be the value of an optimal

solution S∗ ⊆ 1, · · · , n. Note that, in contrast with previous examples, this is a maximizationproblem. Hence, we aim at proving that OPT

2 ≤ V alueOfComputedSolution ≤ OPT .To prove the approximation ratio, let T ⊆ 1, · · · , n be the computed solution and let∑

i∈Twi = SOL be its value. Clearly,

∑1≤i≤j

wi ≤ SOL ≤ OPT ≤ b. Let j ≥ 1 be the smallest

integer such that j + 1 is NOT in T . By definition of the algorithm,∑

1≤i≤j+1wi = wj+1 +∑

1≤i≤jwi > b and, because the wi’s are ordered, wj+1 ≤ min

1≤i≤jwi = wj . Finally, min

1≤i≤jwi ≤∑

1≤i≤j

wi

j (because the average of w1, · · · , wj cannot be less than the minimum wi).It follows that

∑1≤i≤j

wi ≤ SOL ≤ OPT ≤ b < wj+1 +∑

1≤i≤jwi ≤ (1 + 1/j)

∑1≤i≤j

wi ≤

(1 + 1/j)SOL ≤ 2SOL (because j ≥ 1) and obviously 2SOL ≤ 2OPT .Summing up, OPT ≤ 2SOL ≤ 2OPT , i.e., OPT

2 ≤ SOL ≤ OPT .

A polynomial-time approximation scheme (PTAS) is a family of algorithms whichtake an instance of an optimization problem and a parameter ε > 0 and, in polynomial time inthe size of the instance (not necessarily in ε), produces a solution that is within a factor 1 + εof being optimal.

That is, when ε tends to 0, the solution tends to an optimal one, while the complexityincreases (generally, the complexity is of the form O(nf(1/ε)) for some function f).

We now present a PTAS algorithm for the Knapsack Problem. Algorithm 16 generalizesthe previous greedy algorithm. Instead of computing a greedy solution “from scratch”, Al-gorithm 16 depends on some fixed integer k = d1/εe. For every subset X of size at most k,Algorithm 16 starts from X and uses the greedy algorithm to complete (try to improve) X.Then, Algorithm 16 keeps the best solution that it met in this way. Intuitively, Algorithm 16aims at using the greedy algorithm but starting from a “best” partial solution (since it checksall subsets of size ≤ k, in particular, there is one iteration for which it will consider the heaviestk elements of an optimal solution, and it will only need to improve this “already good” partialsolution “not too badly”). Hence, the larger k (the smaller ε), the best will be the obtainedsolution (the approximation ratio) but the higher will be the time-complexity (since we need atleast to check all subsets of size at most k).

25

Page 26: Lecture on Graphs and Algorithms (Master 1)Lecture on Graphs and Algorithms (Master 1) Nicolas Nisse Abstract These are lecture notes of the course I gave, at Master 1 level. The main

Algorithm 16 PTAS for the Knapsack Problem

Require: A set of integers S = w1, · · · , wn, b ∈ N and a real ε > 0.

Ensure: A subset T ⊆ 1, · · · , n of items such that∑i∈T

wi ≤ b1: best = ∅2: best cost = 03: k = d1/εe4: Sort S such that w1 ≥ w2 ≥ · · · ≥ wn.5: for Any subset X ⊆ S of size at most k do6: //Complete X using the Greedy Algorithm. That is:7: Let T = X and k′ = |X| ≤ k.8: Let total weight =

∑i∈X wi

9: Up to renaming the elements in S \X, let us assume that S \X = w1, · · · , wn−k′ withw1 ≥ w2 ≥ · · · ≥ wn−k′ .

10: for i = 1 to n− k′ do11: if total weight+ wi ≤ b then12: Add i to T13: Add wi to total weight14: end if15: end for16: if total weight > best cost then17: Replace best by T18: end if19: end for20: return T

Theorem 16 Algorithm 16 is a PTAS for the Knapsack problem.

Proof. Algorithm 16 computes a valid solution in time-complexity O(nd1/εe+1). Indeed, thereare O(nk) subsets of size at most k in a ground-set with n elements.

Then, Algorithm 16 is a (1+ε)-approximation algorithm for the Knapsack problem. Indeed,consider an optimal solution OPT and let X∗ = i1, · · · , ik be the k items with largest weightin OPT (show that, if OPT consists of less than k items, then Algorithm 16 computes anoptimal solution). Consider the iteration of Algorithm 16 when it considers X∗. The proof is a(not difficult) adaptation of the proof of Theorem 15.

Actually, we can do better. Indeed, the Knapsack Problem admits a fully polynomial-time approximation scheme (FPTAS) algorithm, that is an algorithm that computes asolution that is within a factor 1 + ε of being optimal in time polynomial both in the sizeof the instance AND in 1/ε.

Part III

Parameterized Algorithms [4]

7 Introduction to Parameterized Algorithms (with Vertex Cover as

toy example)

Until now, we have evaluated the “quality/efficiency” of algorithms (resp., the “difficulty” ofproblems we have met) in function of the size s (generally, in graph’s problems, the number of

26

Page 27: Lecture on Graphs and Algorithms (Master 1)Lecture on Graphs and Algorithms (Master 1) Nicolas Nisse Abstract These are lecture notes of the course I gave, at Master 1 level. The main

vertices and/or edges) of the instances. Very roughly, a problem is considered as “easy” if thereexists an algorithm for solving it in time polynomial in s. If no such algorithm is known (allknown algorithms are exponential in s), the problem is said “difficult” (NP -hard).

On the other hand, we have seen that problems that are “difficult” in general may be “easy”in some particular classes of instances. For instance, the Vertex Cover problem is NP-hardin general graphs but can be solved in polynomial-time when restricted to bipartite graphs(Theorem 5).

Very roughly, the Parameterized Complexity aims at evaluating the complexity (here weonly focus on time-complexity) of an algorithm/a problem not only as a function of the sizeof the input but also as a function of other parameters of the instance/problem. For instance,in graphs, appropriated parameters may be the diameter, the maximum degree, the minimumvertex cover (i.e., in the case of the Vertex Cover problem, the size of the solution itself),etc.

7.1 First Approach: deciding if vc(G) ≤ k?

Recall that a vertex cover K ⊆ V of a graph G = (V,E) is a subset of vertices such thatK ∩ e 6= ∅ for all e ∈ E. Moreover, recall that vc(G) denotes the minimum size of a VertexCover in G. In Section 2.3, we have already seen that the following algorithm computes aminimum-size Vertex Cover in time O∗(2|V |).

Algorithm 7 Naive Algorithm for Minimum Vertex Cover (reminder)

Require: A graph G = (V,E).Ensure: A minimum Vertex Cover of G.

1: K ← V .2: for every S ⊆ V do3: if S is a vertex cover of G and |S| < |K| then4: K ← S.5: end if6: end for7: return K

Let us (slightly) simplify the question. Let k ∈ N be a fixed parameter. Instead of lookingfor vc(G) (or a Vertex Cover of minimum size), let us “only” ask whether G has some VertexCover of size ≤ k (we may also ask to compute a minimum Vertex Cover of G given that wealready know that vc(G) ≤ k).

Algorithm 17 1st Algorithm to decide if vc(G) ≤ k, where k ∈ N is a fixed parameter.

Require: A graph G = (V,E).Ensure: A minimum Vertex Cover of G (if vc(G) ≤ k) or V (if vc(G) > k).

1: K ← V .2: for every S ⊆ V , |S| ≤ k do3: if S is a vertex cover of G and |S| < |K| then4: K ← S.5: end if6: end for7: return K

Exercise 18 Show that Algorithm 17 has time-complexity O∗(|V |k).

27

Page 28: Lecture on Graphs and Algorithms (Master 1)Lecture on Graphs and Algorithms (Master 1) Nicolas Nisse Abstract These are lecture notes of the course I gave, at Master 1 level. The main

Compare O∗(|V |k) and O∗(2|V |) when, for instance, |V | = 104 and k = 10.

Hence, if we a priori know that the graph into consideration has “small” vertex cover (atmost k), the above algorithm is much more efficient than the previous one. We show below thateven better algorithm can be designed. For this purpose, we need the following lemma:

Lemma 9 Let G = (V,E) be a graph and x, y ∈ E. vc(G) = minvc(G \ x), vc(G \ y)+ 1Intuition: for any edge xy, any minimum vertex cover contains at least one of x or y

Proof. Let S ⊆ V be any vertex cover of G \ x. Then S ∪ x is a vertex cover of G. Hencevc(G) ≤ vc(G \ x) + 1 (symmetrically for G \ y)

Let S ⊆ V be any vertex cover of G. At least one of x or y is in S. If x ∈ S then S \ xvertex cover of G \x. Hence vc(G \x) ≤ vc(G)− 1. Otherwise, if y ∈ S, then S \ y vertex coverof G \ y and vc(G \ y) ≤ vc(G)− 1.

Algorithm 18 Branch & Bound Algo. to decide if vc(G) ≤ k, where k ∈ N is a fixed parameter.

Require: A graph G = (V,E) and an integer `≤ k.Ensure: The minimum size of a Vertex Cover of G if vc(G) ≤ ` or ∞ otherwise.

1: if ` = 0 and |E| > 0 then2: return ∞3: else4: if |E| = 0 then5: return 06: else7: Let u, v ∈ E be any edge8: Let x = Algorithm 18(G \ u, `− 1) and y = Algorithm 18(G \ v, `− 1)9: return minx, y+ 1

10: end if11: end if

Exercise 19 Using Lemma 9, prove the correctness of Algorithm 18.Show that the recursive depth is at most k. Deduce that Algorithm 18 has time-complexityO(2k|E|).

Adapt Algorithm 18 to return a minimum vertex cover of G if vc(G) ≤ k.

Lemma 10 Let G = (V,E) be any simple graph. If vc(G) ≤ k, then |E| ≤ k(|V | − 1).

Proof. Let K ⊆ V be a vertex cover with |K| ≤ k. Note that G − K induces a stable set.Hence, every edge of G is incident to a vertex in K (it is the definition of a vertex cover).Finally, each vertex in K is adjacent to at most |V | − 1 edges.

It follows that:

Corollary 3 Algorithm 18 has time-complexity O(k2k · |V |).

Hence, Algorithm 18 is linear in the order of the graph! Note that Vertex Cover is NP-hard,but we proved that the combinatorial complexity does not come from the order of the graphbut from its structure. That is, the Vertex Cover problem can be solved in linear time (inthe size of the input) in the class of graphs with bounded (fixed) minimum size of a vertexcover. Compare the complexity of Algorithm 18 with the complexity of Algorithm 17 when, forinstance, |V | = 104 and k = 10.

28

Page 29: Lecture on Graphs and Algorithms (Master 1)Lecture on Graphs and Algorithms (Master 1) Nicolas Nisse Abstract These are lecture notes of the course I gave, at Master 1 level. The main

The key difference between the time-complexity of Algorithm 17, O(|E||V |k), and the oneof Algorithm 18, O(k2k · |V |), that are both polynomial in |V | and exponential in k, is that,in the latter case, the polynomial on |V | does not depend on k. That is, in Algorithm 18,the dependencies in k and |V | are “separated”. Such an algorithm is called a Fixed ParameterTractable (FPT) algorithm, parameterized by the size of the solution (the size of the vertexcover).

7.2 Fixed Parameter Tractable (FPT) Algorithms and Kernelization

We don’t aim at giving a formal definition of parameterized complexity and refer to, e.g., [4]for more precise definition. As usual, we moreover focus on graphs.

Let G be the set of all graphs. A graph parameter is any function p : G → N (e.g., diameter,maximum degree, minimum size of a vertex cover, minimum size of a dominating set, etc.).

Roughly, a parameterized problem (Π, p) is defined by a problem Π (here on graphs) anda parameter p. The key point is to understand the behaviour of the time-complexity of analgorithm for solving Π not only as a function of n, the size of the instance, but also as afunction of the value of the parameter p.

An algorithm A for solving (Π, p) is said Fixed Parameter Tractable (FPT) if there existsa computable function f : N → N, such that the time-complexity of A can be expressed asO(f(p(G))nO(1)), where n is the size of the input graph G. Note that the polynomial in n isindependent on p(G) and f depends only on the parameter p(G). A parameterized problem(Π, p) is FPT if it admits a FPT algorithm, parameterized by p, for solving it.

For instance, Algorithm 18 shows that the Vertex Cover problem is FPT when parameterizedby the size of the solution. Another example is any FPTAS algorithm, that can be seen as aFPT (approximation) algorithm parameterized by 1/ε.

To conclude this subsection, let us present a particular kind of FPT algorithms called Ker-nelization algorithms. A natural way to tackle difficult problems is to try to reduce the size ofthe input (e.g., in the case of graphs, to “limit” the problem to the connected components of agraph, or to its 2-connected components...).

Precisely, given a parameterized problem (Π, p), a kernelization algorithm replaces an in-stance (I, p(I)) by a “reduced” instance (I ′, p′(I ′)) (called problem kernel) such that

1. p′(I ′) ≤ g(p(I)) , |I ′| ≤ f(p(I)) for some computable functions f and g only dependingon p(I) (not on |I|)13,

2. (I, p(I)) ∈ Π if and only if (I ′, p′(I ′)) ∈ Π, and

3. reduction from (I, p(I)) to (I ′, p′(I ′)) has to be computable in polynomial time (in |I| +p(I)).

Hence, if a parameterized problem (Π, p) admits a Kernelization algorithm that transformsa n-node graph G and parameter p(G) = k into an equivalent graph G′ with size f(n) (forsome computable function f) and parameter k′ = p′(G′) ≤ g(k) (for some computable func-tion g) in time (n + p(G))O(1), then (Π, k) admits a FPT algorithm with time complexitynO(1) +O(2f(g(k))): first reduce G to G′ and then exhaustive search in G′ with parameterk′ ≤ g(k). Note the difference between this complexity and the one of Algorithm 18 (alsoFPT): in the latter one, the terms depending on k and n are multiplied, while here it is a sum.More generally, it is easy to prove (while a bit counter-intuitive) that:

13A kernel G′ is said linear (resp., quadratic, single exponential...) if |G′| = O(k) (resp., |G′| = O(k2),|G′| = O(2k),...).

29

Page 30: Lecture on Graphs and Algorithms (Master 1)Lecture on Graphs and Algorithms (Master 1) Nicolas Nisse Abstract These are lecture notes of the course I gave, at Master 1 level. The main

Theorem 17 (Bodlaender et al. 2009) A parameterized problem is FPT if and only if it isdecidable and has a kernelization algorithm.

7.3 A first Kernelization Algorithm for Vertex Cover

We aim at improving Algorithm 18.

Lemma 11 Let G = (V,E) be a graph and v ∈ V with degree > k. Then v belongs to everyvertex cover K of size at most k

Proof. Indeed, if v /∈ K, all its neighbors must belong to it and |K| > k.

Lemma 12 Let G = (V,E) be a graph. If vc(G) ≤ k and no vertex of G has degree > k. Then|E| ≤ k2

Proof. Each of the ≤ k vertices of a Vertex Cover covers ≤ k edges (see proof of Lem. 9).

The following algorithm to decide if vc(G) ≤ k proceeds as follows. While there is a “high”degree node, add it to the solution. When there are no such nodes, either it remains too muchedges to have a small vertex cover. Otherwise, apply brute force algorithm (e.g., Algorithm 18)to the remaining “small” graph.

Algorithm 19 Kernelization Alg. to decide if vc(G) ≤ k, where k ∈ N is a fixed parameter.

Require: A graph G = (V,E) and an integer `≤ k.Ensure: The minimum size of a Vertex Cover of G if vc(G) ≤ ` or ∞ otherwise.

1: Let I ⊆ V be the set of isolated vertices in G. Remove I from G2: if |E| = 0 then3: return 04: else5: if ` = 0 then6: return ∞7: else8: if G has no vertex of degree > ` and |E| > `2 then9: return ∞

10: else11: if G has no vertex of degree > ` then12: return Algorithm 18(G, `)13: else14: Let v be a vertex of degree > `15: return Algorithm 19(G \ v, `− 1) + 116: end if17: end if18: end if19: end if

Exercise 20 Using Lemmas 11 and 12, prove the correctness of Algorithm 19.Show that Algorithm 19 has time-complexity O(2kk2 + k|V |). Adapt Algorithm 19 to return aminimum vertex cover of G if vc(G) ≤ k.

Note that previous algorithm relies on a quadratic kernel. Compare the complexity ofAlgorithm 19 with the complexity of Algorithm 18 when, for instance, |V | = 104 and k = 10.

30

Page 31: Lecture on Graphs and Algorithms (Master 1)Lecture on Graphs and Algorithms (Master 1) Nicolas Nisse Abstract These are lecture notes of the course I gave, at Master 1 level. The main

8 Toward tree-decompositions, Graph Minor Theory and be-yond

In this last section, we focus on particular graph classes. Precisely, we will start with trees,then generalize the proposed method to k-trees and then to graphs with bounded treewidth. Wewill then conclude with planar graphs and beyond. Along the way, we will continue to use ourfavorite problem, namely Vertex Cover, as an illustrative example.

8.1 Minimum (weighted) Vertex Cover in trees

Let us start with the problem of computing a minimum-size vertex cover (as it has been studiedmany times above). That is, given a tree T = (V,E), the goal is to compute a set K ⊆ V ,such that ∀e ∈ E, e ∩K 6= ∅, and |K| is minimum subject to this property. Recall that vc(T )denotes the minimum size of a vertex cover in T .

Prove that any tree is a bipartite graph (e.g., use a BFS). So, by Konig’s theorem (Th. 5)and, e.g., the Hungarian method (Th. 4), vc(T ) can be computed in polynomial time in any treeT . We aim at giving here a simpler algorithm in the case of trees. It is based on the followinglemma whose proof is left to the reader.

Lemma 13 Let G = (V,E) be any graph with a vertex v of degree 1. Let u be the uniqueneighbor of v and let K be a vertex cover of G.Then, K ∩ u, v 6= ∅, and K ′ = (K \ v) ∪ u is a vertex cover of G such that |K ′| ≤ |K|.

Notation. Let T = (V,E) be a tree and r ∈ V be any vertex. Let us denote by Tr the tree Trooted in r. For any v ∈ V , the children of v in Tr are the neighbors of v whose distance to ris greater than dist(r, v). The parent of v in Tr (if v is not the root r) is the unique neighborof v that is not a children of v. The descendants of v in Tr are all vertices w such that v is aninternal vertex of the path between r and w in T (such a path is unique by Exercise 2). Finally,the subtree Tv rooted at v in Tr is the subtree induced by v and its descendants. A leaf in arooted tree is any vertex v 6= r with degree 1.

Algorithm 20 Greedy Algorithm for Minimum Vertex Cover in trees

Require: A tree T = (V,E) rooted in any arbitrary vertex r ∈ V .Ensure: A minimum Vertex Cover of T .

1: if E = ∅ then2: return ∅3: else4: Let v ∈ V be any non-leaf vertex maximizing the distance with r (possibly r = v).5: Let T ′ be the tree (rooted in r) obtained from T by removing v and all its children.

// Prove that children of v are leaves and so that T ′ is a tree (rooted in r)6: return v ∪Algorithm 20(T ′).7: end if

Theorem 18 Algorithm 20 computes a minimum Vertex Cover of any tree T in linear time.

Proof. Let us first prove its correctness. Let Tr be a rooted tree, v be a non-leaf maximizingthe distance with r (possibly v = r) and T ′ be defined as in Algorithm 20 (i.e., T ′ is thetree rooted in r obtained from T by removing v and all its leaves neighbors). We claim thatvc(T ) = 1 + vc(T ′). Indeed, if K ′ is a minimum vertex cover of T ′, then K ′ ∪ v is a vertex

31

Page 32: Lecture on Graphs and Algorithms (Master 1)Lecture on Graphs and Algorithms (Master 1) Nicolas Nisse Abstract These are lecture notes of the course I gave, at Master 1 level. The main

cover of T of size |K ′|+1 = vc(T ′)+1 ≥ vc(T ). On the other hand, let K be a minimum vertexcover of T . By Lemma 13, we may assume that v ∈ K. Hence, K ′ = K \ v is a vertex coverof T ′ and so |K ′| = vc(T )− 1 ≥ vc(T ′). By induction on |V (T )|, Algorithm 20 returns a vertexcover of size 1 + vc(T ′). By the claim, it is then an optimal vertex cover of size vc(T ). Hence,Algorithm 20 is correct.

For the time-complexity, there at most |V (T )| recursive calls (since |V (T ′)| < |V (T )|). Themain (most time consuming) step at each call consists in finding the vertex v. It can be donein constant time by, for instance (without more details), using a pre-processing that orders thevertices of Tr by non-increasing distance from r, e.g., by a “BFS-like” ordering: first the leaves,then the parents of only leaves, then the parents of only parents of only leaves and so on (thisis called a topological ordering of the vertices of Tr).

Hence, minimum (size) Vertex Cover is almost trivial in trees, so let us “complexify” a bitthe problem.

Minimum weighted Vertex Cover in trees. Given a tree T = (V,E) with weight functionw : V → R+ on the vertices, the goal is to compute a set K ⊆ V , such that ∀e ∈ E, e ∩K 6= ∅,and w(K) =

∑v∈K

w(v) is minimum subject to this property. Let vc(T,w) denote the minimum

weight of a vertex cover in (T,w).

Exercise 21 Give an example of a weighted tree (you may restrict your example to be a star,i.e., a tree with at most one vertex with degree > 1) such that vc(T ) = 1 (minimum size) andthe number of vertices in a minimum weighted Vertex Cover is arbitrary large.

In what follows, we present a linear-time dynamic programming algorithm to computevc(T,w) and a vertex cover with this weight.

Let (Tr, w) be a weighted rooted tree (not reduced to a single vertex) and let r1, · · · , rd bethe children of r. For every 1 ≤ i ≤ d, let Ti be the subtree of Tr rooted in ri. The proof of thenext lemma is left to the reader.

Lemma 14 Let K be any vertex cover of Tr. Either r ∈ K and then, for every 1 ≤ i ≤ d,K ∩ V (Ti) is a vertex cover of Ti. Or r /∈ K and then, for every 1 ≤ i ≤ d, K ∩ V (Ti) is avertex cover of Ti with ri ∈ K ∩ V (Ti).

Previous lemma suggests that, given a weighted rooted tree (Tr = (V,E), w), our dynamicprogramming algorithm will proceed bottom-up (from leaves to root) by, for every vertex v ∈ V ,keeping track of vc(Tv, w) (the minimum weight of a vertex cover of (Tv, w)) but also of vc′(Tv, w)defined as the minimum weight of a vertex cover of Tv containing v (i.e., vc′(Tv, w) is theminimum weight of any vertex cover among all vertex covers of (Tv, w) containing v).

From Lemma 14 and by induction on |V (T )|, the proof of next theorem easily follows.

Theorem 19 Algorithm 21 computes a minimum weight Vertex Cover of any vertex-weightedtree (T,w) in linear time.

8.2 2-trees

In the sequels, we will extend Algorithm 21 to some graph class generalizing trees (graphs withbounded treewidth). To make the next algorithms easier to understand, let us first go one stepfurther. For this purpose, a key notion is the one of separators in graphs. Given a graphG = (V,E) and X,Y ⊆ V , X ∩ Y = ∅, a set S ⊆ V \ (X ∪ Y ) is a (X,Y )-separator in G if, for

32

Page 33: Lecture on Graphs and Algorithms (Master 1)Lecture on Graphs and Algorithms (Master 1) Nicolas Nisse Abstract These are lecture notes of the course I gave, at Master 1 level. The main

Algorithm 21 Dynamic Programming Algorithm for Minimum weight Vertex Cover in trees

Require: A weighted tree (Tr = (V,E), w : V → R+) rooted in any arbitrary vertex r ∈ V 6= ∅.Ensure: (K,K ′) where K is a minimum Vertex Cover of (Tr, w) (of weight vc(T,w)) and K ′

is a minimum Vertex Cover of (Tr, w) containing r (of weight vc′(Tr, w))1: if V = r then2: return (∅, r) // of weight respectively 0 and w(r)3: else4: Let r1, · · · , rd be the children of r and, for every 1 ≤ i ≤ d, let Ti be the subtree of Tr

rooted in ri.5: for i = 1 to d do6: Let (Ki,K

′i) = Algorithm 21(Ti, w|V (Ti))//Ki is a minimum weight vertex cover of Ti, i.e., of weight vc(Ti, w|V (Ti))//K ′i is a minimum weight vertex cover of Ti containing ri, i.e., of weight

vc′(Ti, w|V (Ti))7: end for8: Let K ′ = r ∪

⋃1≤i≤d

Ki. // Show it is a min. weight VC of (T,w) containing r

9: Let K ′′ =⋃

1≤i≤dK ′i. // Show it is a min. weight VC of (T,w) not containing r

10: Let K ∈ K ′,K ′′ such that w(K) = minw(K ′), w(K ′′).// Show it is a min. weight VC of (T,w)

11: return (K,K ′).12: end if

every u ∈ X and v ∈ Y , every u, v-path goes through a vertex in S (equivalently, u and v arein distinct connected components of G[V \ S]). A set S ⊂ V is a separator in G if there existu, v ∈ V \ S such that S is a (u, v)-separator (or u, v-separator).

The class of 2-trees is defined recursively as follows. A complete graph (clique) K3 with 3vertices (triangle) is a 2-tree. Given any 2-tree H with some edge u, v ∈ E(H), the graphobtained from H by adding a new vertex x adjacent to u and v is a new 2-tree. The recursiveconstruction of a 2-tree naturally leads to the definition of a corresponding “building tree”.

Given a 2-tree G = (V,E), a tree-decomposition (T,X = Xt | t ∈ V (T )) of G is definedrecursively as follows. If G = K3 is reduced to a clique with vertices u, v and w, its correspondingtree-decomposition consists of a tree T reduced to a single node t0 and X = Xt0 = u, v, w ⊆V . If G is obtained from a 2-tree H, with u, v ∈ E(H), by adding a vertex x adjacentto u and v, a tree-decomposition (TG,XG = XG

t | t ∈ V (TG)) of G is obtained from anytree-decomposition (TH ,XH = XH

t | t ∈ V (TH)) of H by considering any node s ∈ V (TH)such that u, v ∈ XH

s (show that such a node exists by induction on |V |) and build TG from THby adding a new node nx adjacent to s, and XG = XH ∪ Xnx = u, v, x ⊆ V . Note that a2-tree may admit several decompositions.

Intuitively, each node of TG corresponds to a subset of vertices of G inducing a maximalclique (triangle) of G. Hence, (TG,XG) “organizes” the triangles of G in a tree-like fashion whilesatisfying some “connectivity properties” as described by the first 2 items of Lemma 15.

Lemma 15 Let G = (V,E) be a 2-tree, (T,X ) be a tree-decomposition of G and e = u, v ∈E(T ). Let Tu (resp. Tv) be the subtree of T \ e = (V (T ), E(T ) \ e) containing u (resp., v)and Gu = G[

⋃t∈V (Tu)

Xt] and Gv = G[⋃

t∈V (Tv)

Xt]. Then,

• S = Xu ∩Xv = x, y where x, y ∈ E(G);

33

Page 34: Lecture on Graphs and Algorithms (Master 1)Lecture on Graphs and Algorithms (Master 1) Nicolas Nisse Abstract These are lecture notes of the course I gave, at Master 1 level. The main

• S separates V (Gu) \S from V (Gv) \S (every path from a vertex in V (Gu) \S to a vertexin V (Gv) \ S goes through S);

// in particular, there are no edges between V (Gu) \ S and V (Gv) \ S.

Moreover, let Q ⊆ S \ ∅. Prove that, because S is a (V (Gu) \ S, V (Gv) \ S)-separator:

• If K is a vertex cover of G with K ∩ S = Q, then K ′ = K ∩ V (Gu) is a vertex cover ofGu with K ′ ∩ S = Q.

• If K is a vertex cover of Gu with K ∩ S = Q, then there exists a vertex cover K ′ of Gsuch that K = K ′ ∩ V (Gu) (and, in particular, K ′ ∩ S = Q).

The key points are that Vertex Cover is a “local” problem and that 2-trees have small-sizeseparators. Intuitively, extending a vertex cover K of Gu to some vertex cover of G does notdepend on the whole K but only on K∩S where S is a separator between Gu and the remindingof G. When |S| is “small”, this can be done efficiently.

Algorithm 22 Dynamic Programming Algorithm for Minimum size Vertex Cover in 2-trees

Require: A 2-tree G = (V,E) and a tree-decomposition (Tr,X ) of G rooted in some vertexr ∈ V (Tr).

Ensure: For every Q ⊆ Xr, a minimum-size Vertex Cover KQ of G such that KQ ∩ Xr = Qand KQ =∞ if no vertex cover K of G is such that K ∩Xr = Q.

1: if V (Tr) = r and Xr = u, v, w then2: return (KQ)Q⊆Xr with KQ = Q if |Q| > 1 and KQ =∞ otherwise.3: else4: Let r1, · · · , rd be the children of r and, for every 1 ≤ i ≤ d, let Ti be the subtree of Tr

rooted in ri. Let Xi = Xt ∈ X | t ∈ V (Ti) and let Gi = G[⋃

X∈Xi

X] be the subgraph

induced by the vertices in the sets in Xi.5: for i = 1 to d do6: Let (Ki

Q′)Q′⊆Xri= Algorithm 22(Gi, (Ti,Xi))

7: end for8: for Q ⊆ Xr do9: if |Q| ≤ 1 then

10: Let KQ =∞11: else12: for i = 1 to d do13: Let Qi ⊆ Xri be such that Qi ∩ Xr = Q ∩ Xri and, among such sets, |Ki

Qi| is

minimum. //abusing notations, |K| =∞ if K =∞14: end for

15: Let KQ = Q ∪d⋃i=1

KiQi

.

16: end if17: end for18: return (KQ)Q⊆Xr .19: end if

Theorem 20 Algorithm 22 is correct and has time-complexity O(n) where n is the number ofvertices of G.

34

Page 35: Lecture on Graphs and Algorithms (Master 1)Lecture on Graphs and Algorithms (Master 1) Nicolas Nisse Abstract These are lecture notes of the course I gave, at Master 1 level. The main

Proof. The proof of correctness is by induction on the number of nodes of T . It is clearly trueif |V (T )| = 1 by lines 1-3 of the algorithm. If |V (T )| > 1 then r has d ≥ 1 children and, by theinduction hypothesis, for every 1 ≤ i ≤ d and Q′ ⊆ Xri , K

iQ′ is a minimum vertex cover of Gi

containing Q′ (or KiQ′ =∞ if Q′ is not a vertex cover of G[Xri ]).

If Q ⊆ Xr is such that |Q| ≤ 1, then Q cannot cover all edges of Xr and so, there are novertex cover K of G with K ∩Xr = Q, and so KQ =∞ (lines 9-10).

Otherwise, Q is a vertex cover of Xr and so there are vertex cover K of G such thatK ∩ Xr = Q (e.g., (V \ Xr) ∪ Q). Let K∗Q be any minimum vertex cover of G such thatK∗Q ∩ Xr = Q. For every 1 ≤ i ≤ d, by Lemma 15, K∗ ∩ V (Gi) is a minimum vertex cover(containing Q ∩ Xri) of Gi. Lines 12-15 precisely consider such sets and so, the set KQ is aminimum vertex cover of G such that K∗Q ∩Xr = Q.

For the complexity, Lines 5-7 needs (by induction)d∑i=1

O(|E(Ti)|) operations. Then, because

|Xt| = 3 for all t ∈ V (T ), then the number of sets Q ⊆ Xr is 23 = O(1), and then the loop inLine 8 has O(1) iterations and the computation of the minima in Line 13 takes constant time.Overall, the complexity is then O(|E(T )|).

Since any tree-decomposition (T,X ) of a 2-tree G with n vertices has O(n) nodes/edges(prove it), this leads to an overall complexity of O(n).

From previous Theorem and Algorithm, we easily get the linear-time Algorithm 23 thatcomputes a minimum vertex cover in any 2-tree.

Algorithm 23 Minimum size Vertex Cover in 2-trees

Require: A 2-tree G = (V,E) and a tree-decomposition (Tr,X ) of G rooted in some vertexr ∈ V (Tr).

Ensure: A minimum-size vertex cover K of G1: (KQ)Q⊆Xr = Algorithm 22(G, (Tr,X )).2: K = V3: for Q ⊆ Xr do4: if |KQ| ≤ |K| then5: K ← KQ //abusing notations, |K| =∞ if K =∞6: end if7: end for8: return K

8.3 k-trees

Let us go a step further. Let k be any integer ≥ 1.The class of k-trees is defined recursively as follows. A complete graph (clique) Kk+1 with

k + 1 vertices is a k-tree. Given any k-tree H with some clique Q of size k in H, the graphobtained from H by adding a new vertex x adjacent to every vertex in Q is a new k-tree.

Given a k-tree G = (V,E), a tree-decomposition (T,X = Xt | t ∈ V (T )) of G is de-fined recursively as follows. If G = Kk+1 is reduced to one clique Q, its corresponding tree-decomposition consists of a tree T reduced to a single node t0 and X = Xt0 = Q ⊆ V . If Gis obtained from a k-tree H, with a clique Q of size k in H, by adding a vertex x adjacent toall vertices in Q, a tree-decomposition (TG,XG = XG

t | t ∈ V (TG)) of G is obtained from anytree-decomposition (TH ,XH = XH

t | t ∈ V (TH)) of H by considering any node s ∈ V (TH)such that V (Q) ⊆ XH

s (show that such a node exists by induction on |V |) and build TG from

35

Page 36: Lecture on Graphs and Algorithms (Master 1)Lecture on Graphs and Algorithms (Master 1) Nicolas Nisse Abstract These are lecture notes of the course I gave, at Master 1 level. The main

TH by adding a new node nx adjacent to s, and XG = XH ∪ Xnx = Q ∪ x ⊆ V . Note thata k-tree may admit several decompositions.

Intuitively, each node of TG corresponds to a subset of vertices of G inducing a maximalclique of G. Hence, (TG,XG) “organizes” the maximal cliques of G in a tree-like fashion whilesatisfying some “connectivity properties” as described by the first 2 items of Lemma 16.

Lemma 16 Let G = (V,E) be a k-tree, (T,X ) be a tree-decomposition of G and e = u, v ∈E(T ). Let Tu (resp. Tv) be the subtree of T \ e = (V (T ), E(T ) \ e) containing u (resp., v)and Gu = G[

⋃t∈V (Tu)

Xt] and Gv = G[⋃

t∈V (Tv)

Xt]. Then,

• S = Xu ∩Xv is a clique of size k in G;

• S separates V (Gu) \S from V (Gv) \S (every path from a vertex in V (Gu) \S to a vertexin V (Gv) \ S goes through S);

// in particular, there are no edges between V (Gu) \ S and V (Gv) \ S.

Moreover, let Q ⊆ S \ ∅. Prove that, because S is a (V (Gu) \ S, V (Gv) \ S)-separator:

• If K is a vertex cover of G with K ∩ S = Q, then K ′ = K ∩ V (Gu) is a vertex cover ofGu with K ′ ∩ S = Q.

• If K is a vertex cover of Gu with K ∩ S = Q, then there exists a vertex cover K ′ of Gsuch that K = K ′ ∩ V (Gu) (and, in particular, K ′ ∩ S = Q).

The key points are that Vertex Cover is a “local” problem and that k-trees have small-sizeseparators (of size k). Intuitively, extending a vertex cover K of Gu to some vertex cover of Gdoes not depend on the whole K but only on K ∩S where S is a separator between Gu and thereminding of G. When |S| is “small”, this can be done efficiently.

Theorem 21 Algorithm 24 is correct and has time-complexity O(2kn) where n is the numberof vertices of any k-tree G.

Proof. The proof of correctness is similar to the one of Algorithm 22.

For the complexity, Lines 5-7 needs (by induction)d∑i=1

O(|E(Ti)|) operations. Then, because

|Xt| = k + 1 for all t ∈ V (T ), then the number of sets Q ⊆ Xr is 2k+1 = O(2k), and then theloop in Line 8 has O(2k) iterations and the computation of the minima in Line 13 takes timeO(2k). Overall, the complexity is then O(2k|E(T )|).

Since any tree-decomposition (T,X ) of a k-tree G with n vertices has O(n) nodes/edges(prove it), this leads to an overall complexity of O(2kn).

From previous Theorem and Algorithm, we easily get the Algorithm 25 that computes, intime O(2kn) a minimum vertex cover in any n-node k-tree.

8.4 Brief introduction to treewidth and tree-decompositions

Hopping to lead to a better intuition, we first give a definition of the treewidth (and tree-decomposition) following the previous sub-sections. Then, we will give an equivalent but moretechnical (?) definition that is (maybe) easier to work with.

Let k ∈ N. A graph is a partial k-tree iff it is a subgraph of a k-tree. The treewidth of agraph G = (V,E), denoted by tw(G), equals the minimum integer k such that G is a partial

36

Page 37: Lecture on Graphs and Algorithms (Master 1)Lecture on Graphs and Algorithms (Master 1) Nicolas Nisse Abstract These are lecture notes of the course I gave, at Master 1 level. The main

Algorithm 24 Dynamic Programming Algorithm for Minimum size Vertex Cover in k-trees

Require: A k-tree G = (V,E) and a tree-decomposition (Tr,X ) of G rooted in some vertexr ∈ V (Tr).

Ensure: For every Q ⊆ Xr, a minimum-size Vertex Cover KQ of G such that KQ ∩ Xr = Qand KQ =∞ if no vertex cover K of G is such that K ∩Xr = Q.

1: if V (Tr) = r and Xr = u, v, w then2: return (KQ)Q⊆Xr with KQ = Q if |Q| > k − 1 and KQ =∞ otherwise.3: else4: Let r1, · · · , rd be the children of r and, for every 1 ≤ i ≤ d, let Ti be the subtree of Tr

rooted in ri. Let Xi = Xt ∈ X | t ∈ V (Ti) and let Gi = G[⋃

X∈Xi

X] be the subgraph

induced by the vertices in the sets in Xi.5: for i = 1 to d do6: Let (Ki

Q′)Q′⊆Xri= Algorithm 22(Gi, (Ti,Xi))

7: end for8: for Q ⊆ Xr do9: if |Q| ≤ k − 1 then

10: Let KQ =∞11: else12: for i = 1 to d do13: Let Qi ⊆ Xri be such that Qi ∩ Xr = Q ∩ Xri and, among such sets, |Ki

Qi| is

minimum. //abusing notations, |K| =∞ if K =∞14: end for

15: Let KQ = Q ∪d⋃i=1

KiQi

.

16: end if17: end for18: return (KQ)Q⊆Xr .19: end if

Algorithm 25 Minimum size Vertex Cover in k-trees

Require: A k-tree G = (V,E) and a tree-decomposition (Tr,X ) of G rooted in some vertexr ∈ V (Tr).

Ensure: A minimum-size vertex cover K of G1: (KQ)Q⊆Xr = Algorithm 24(G, (Tr,X )).2: K = V3: for Q ⊆ Xr do4: if |KQ| ≤ |K| then5: K ← KQ //abusing notations, |K| =∞ if K =∞6: end if7: end for8: return K

37

Page 38: Lecture on Graphs and Algorithms (Master 1)Lecture on Graphs and Algorithms (Master 1) Nicolas Nisse Abstract These are lecture notes of the course I gave, at Master 1 level. The main

k-tree (note that any n-node graph is a partial (n − 1)-tree as subgraph of Kn and so thisparameter is well defined).

Following previous sub-sections, a first way to define a tree-decomposition of a graph is asfollows. Let G = (V,E) be a partial k-tree, i.e., a subgraph of a k-tree H = (VH , EH). Let(T,X = (Xt)t∈V (T )) be a tree-decomposition of H (as defined in previous sub-section). Then,(T,X ∩ V = (Xt ∩ V )t∈V (T )) is a tree-decomposition of G of width at most k. Roughly, thedifference with tree-decompositions of k-trees is that, in a tree-decomposition of a k-tree, thesets Xt (called bags) consist of cliques of size k+ 1, while, in the case of partial k-trees, they aresubgraphs of size at most k+1. However, as we will see below they share the same connectednessproperties. First, let us mention the algorithmic applications of tree-decompositions.

Theorem 22 There exists an algorithm that, given any n-node graph G of treewidth tw(G) anda tree-decomposition of G of width at most tw(G), computes a minimum vertex cover of G intime O(2tw(G) · n).

Proof. Such an algorithm (almost) directly follows Algorithm 25 by modifying the Algorithm 24in the following way. In Line 2, |Q| > k − 1 is replaced by “Q is a vertex cover of Xr”, and inLine 9, |Q| ≤ k − 1 is replaced by “Q is not a vertex cover of Xr”.

The algorithm described in the proof of Theorem 22 is an FPT algorithm to compute aminimum Vertex Cover when the parameter is the treewidth (in contrast with previous FPTalgorithms we have seen so far where the parameter was always the size of the solution, namely,the size k of a vertex cover).

To further exemplify the algorithmic applications of tree-decompositions, let us mention(without any explanation) the celebrated Courcelle’s meta theorem.

Theorem 23 (Courcelle 1990) Every graph property P definable in the monadic second-order logic14 of graphs can be decided in linear time on graphs of bounded treewidth. Thatis, there is a function fP such that P can be decided in time O(fP (k) ·n) in the class of n-nodegraphs with treewidth at most k.

Complexity of treewidth. Theorem 22 (and most of the dynamic programming algorithmsusing tree-decompositions) explicitly requires a “good” (with small width) tree-decompositionas input (Theorem 23 actually requires it implicitly). Unfortunately, the problem of decidingwhether tw(G) ≤ k is NP-complete15. On the positive side, this problem is FPT (with parameterthe width itself)16 and there exists a

√log k-approximation algorithm for the problem17. On

a practical point of view, it is an important research topic to design efficient approximationalgorithms or heuristics that compute “good” tree-decompositions of graphs. The problem canbe solved more “efficiently” in particular graphs classes. For instance, there is a cubic 3/2-approximation algorithm in planar graphs18, however, the complexity of the problem in planargraphs is still open...

14See Chapter 7.4 of [4] for an intuitive definition of MSOL. Examples of such problems include Vertex Cover,Dominating Set, 3-Colouring...

15Stefan Arnborg, Derek G. Corneil, Andrzej Proskurowski: Complexity of finding embeddings in a k-tree.SIAM J. of Discrete Maths 8(2): 277-284 (1987)

16Hans L. Bodlaender, Ton Kloks: Efficient and Constructive Algorithms for the Pathwidth and Treewidth ofGraphs. J. Algorithms 21(2): 358-402 (1996)

17Uriel Feige, Mohammad Taghi Hajiaghayi, James R. Lee: Improved Approximation Algorithms for MinimumWeight Vertex Separators. SIAM J. Comput. 38(2): 629-657 (2008)

18Paul D. Seymour, Robin Thomas: Call Routing and the Ratcatcher. Combinatorica 14(2): 217-241 (1994)

38

Page 39: Lecture on Graphs and Algorithms (Master 1)Lecture on Graphs and Algorithms (Master 1) Nicolas Nisse Abstract These are lecture notes of the course I gave, at Master 1 level. The main

Second definition of treewidth and tree-decomposition. So far, we have given a firstdefinition of tree-decomposition and treewidth in terms of partial k-trees because we hope thatit is a bit more intuitive. Let us now give a more technical definition that does not rely on ak-tree supergraph. Let G = (V,E) be a graph. A tree-decomposition19 of G is a pair (T,X )where T = (V (T ), E(T )) is a tree and X = Xt | t ∈ V (T ) is a family of subsets (called bags)of V such that:

1.⋃

t∈V (T )

Xt = V ;

2. for every e = u, v ∈ E, there exists t ∈ V (T ) such that u, v ∈ Xt;

3. for every v ∈ V , the set t ∈ V (T ) | v ∈ Xt induces a subtree of T .

The width of (T,X ) equals maxt∈V (T )

|Xt| − 1 and the treewidth, tw(G), of G is the mini-

mum width of a tree-decomposition of G (Note that, for any graph G, there is a trivial tree-decomposition consisting of a tree with a single note t such that Xt = V ). The −1 in thedefinition of the width is only there to ensure that tw(G) = 1 if and only if G is a forest (i.e.,all connected components of G are trees).

Exercise 22 Prove that the above definitions of tree-decomposition and treewidth are equivalentto the ones given in terms of partial k-tree.

Let us note that, if a graph G = (V,E) admits a tree-decomposition (T,X ) of width k,then G has an infinity of such decompositions. Indeed, for any t ∈ V (T ), let T ′ be the treeobtained from T by adding a (leaf) vertex t′ adjacent to t and X ′ = X ∪Xt′ = Xt, then provethat (T ′,X ′) is a tree-decomposition of G with width k. To avoid this pathological cases (andsimplify next proofs), let us first show that we can always restrict ourself to tree-decomposition(T,X ) such that, for every t, t′ ∈ V (T ), Xt \Xt′ 6= ∅.

Given a graph G = (V,E) and an edge uv ∈ E, let G/uv be the graph obtained by contract-ing the edge uv defined as V (G/uv) = (V \ u, v) ∪ x and E(G/uv) = (E \ e ∈ E | e ∩ u 6=∅ or e ∩ v 6= ∅) ∪ xw | w ∈ N(u) ∪N(v) (roughly, u and v are identified).

Exercise 23 Let G = (V,E) be a graph and (T,X ) be tree-decomposition of G with width k.Let tt′ ∈ E(T ) such that Xt′ ⊆ Xt. Let T ′ = T/tt′ (with x being the new vertex resulting fromthe identification of t and t′) and X ′ = (X \ Xt, Xt′) ∪ Xx = Xt. Show that (T ′,X ′) is atree-decomposition of G with width k.

From now on, every considered tree-decomposition (T,X ) will be assumed to satisfy thatfor every t, t′ ∈ V (T ), Xt \Xt′ 6= ∅. Note that, for such a tree-decomposition (T,X ) of a graphG = (V,E), for every t ∈ V (T ) leaf of T , there exists v ∈ V such that v ∈ Xt and v /∈ Xt′ forevery t′ ∈ V (T ) \ t.

The next exercise probably describes the main property of tree-decompositions.

Exercise 24 Let G = (V,E) be a graph and (T,X ) be tree-decomposition of G.

• Let t ∈ V (T ) and let T1, · · · , Td be the components of T \ t. For every 1 ≤ i < j ≤ d,Xt separates

⋃t′∈Ti

Xt′ \Xt and⋃

t′∈TjXt′ \Xt in G.

19Neil Robertson, Paul D. Seymour: Graph minors. IV. Tree-width and well-quasi-ordering. J. Comb. Theory,Ser. B 48(2): 227-254 (1990)

39

Page 40: Lecture on Graphs and Algorithms (Master 1)Lecture on Graphs and Algorithms (Master 1) Nicolas Nisse Abstract These are lecture notes of the course I gave, at Master 1 level. The main

• Let e = tt′ ∈ E(T ) and let T1 (resp., T2) be the component of T \ e containing t (resp.,containing t′). Xt ∩Xt′ is a (

⋃h∈T1

Xh \Xt,⋃h∈T2

Xh \Xt) separator.

Before going further, let us define an important notion. A graph H is a minor of a graphG, denoted by H G, if H is a subgraph of a graph G′ that is obtained from G by a sequenceof contraction(s) of edges. In other words, H is a minor of G if it can be obtained from G bysequentially removing vertices, edges and/or contracting edges.

Exercise 25 Prove that,

• if H G, then tw(H) ≤ tw(G); // treewidth is minor-closed

• tw(C) = 2 for any cycle C;

• tw(G) = 1 if and only if G is a forest;

• tw(Kn) = n− 1 for any n ≥ 1;

• Let G be a graph containing a clique K as subgraph. Then, for every tree-decomposition(T,X ) of G, there exists t ∈ V (T ) with K ⊆ Xt, and so tw(G) ≥ |K| − 1;

• Let Gn×m be the n×m grid. Then, tw(Gn×m) ≤ minn,m.

Above, we tried to make it clear that graphs with bounded treewidth have “simple” structurethat can be efficiently used for algorithmic purposes. Several “real-life” graphs have boundedtreewidth20, but, unfortunately, it is not true in many important fields of applications (Internet,road networks...). Therefore, it is natural to ask what is the structure of graphs with largetreewidth. Such a “dual” structure for graphs with large treewidth would also be useful forproving lower bounds for the treewidth of graphs (e.g., we will use it to give the exact valueof treewidth for grids). One important result of Robertson and Seymour in their Graph Minortheory (see below for more details) is the characterization of such an obstruction for smalltreewidth.

Given a graph G = (V,E) and X,Y ⊆ V , X and Y are touching if X ∩ Y 6= ∅ or if thereare x ∈ X and y ∈ Y such that xy ∈ E. A bramble B in G is a family of subsets of V pairwisetouching (i.e., for every B,B′ ∈ B, B and B′ are touching). The order of B is the minimum sizeof a transversal of B, i.e., the minimum size of a set T ⊆ V such that T ∩B 6= ∅ for all B ∈ B.The bramble number, BN(G), of a graph G is the maximum order of a bramble in G.

Theorem 24 (Seymour and Thomas 1993) 21 For any graph G, tw(G) = BN(G)− 1.

An intuitive way to understand (and prove) the above theorem is by considering the equiv-alence between tree-decompositions and graph searching games22.

As a consequence of previous theorem, let us show the following lemma.

Lemma 17 Let Gn×m be the n×m grid. Then, tw(Gn×m) = minn,m.20e.g., Mikkel Thorup: All Structured Programs have Small Tree-Width and Good Register Allocation. Inf.

Comput. 142(2): 159-181 (1998)21Paul D. Seymour, Robin Thomas: Graph Searching and a Min-Max Theorem for Tree-Width. J. Comb.

Theory, Ser. B 58(1): 22-33 (1993)22See Section 4.1 in Nicolas Nisse: Network Decontamination. Distributed Computing by Mobile Entities 2019:

516-548

40

Page 41: Lecture on Graphs and Algorithms (Master 1)Lecture on Graphs and Algorithms (Master 1) Nicolas Nisse Abstract These are lecture notes of the course I gave, at Master 1 level. The main

Proof. Let us assume that n ≤ m. The upper bound follows from Exercise 25. For the lowerbound, by Theorem 24, let us exhibit a bramble of order n+ 1. Given a grid, a cross consists ofthe union of any row plus any column. Let G′ be the subgrid obtained from Gn×m by removingits first row and its first column. The desired bramble consists of the first row, the first columnminus its vertex in the first row, and all crosses of G′.

Intuitively, a bramble with large order in a graph G may be seen as a large grid or as a largeclique minor in G. The following result shows that any planar graph23 has a large treewidth ifand only if it admits a large grid as minor.

Theorem 25 (Grid Theorems) [Robertson and Seymour 198624, Kawarabayashi and Kobayashi201225, Chuzhoy and Tan 201926]Any planar graph G with treewidth Ω(k) has an k × k grid as minor.Any graph G with treewidth Ω(k9poly log(k)) has an k × k grid as minor.There are graphs with treewidth Ω(k2 log(k)) without any k × k grid as minor.

One first interesting application of previous theorem is the framework of bidimensionalitytheory that we present with an example below.

Bidimensionality. Let us consider a function fP : graphs → N and consider the problemP that, given a graph G and an integer k, aims at deciding whether fP (G) ≤ k ≤ |V (G)|. Letus assume that P is closed under taking minor, i.e., fP (H) ≤ fP (G) for every H G, that theproblem can be decided in time O(2tw(G)n) and that fP (Gn×n) = Ω(n2) where Gn×n is the gridof side n. The Vertex Cover problem is an example of such a problem.

Theorem 26 (Demaine and Hajiaghayi 2008) 27 Such a problem P can be solved in sub-exponential time O(2

√npoly(n)) in the class of n-node planar graphs.

Proof. (Sketch) Consider the following algorithm to decide whether fP (G) ≤ k. First, iftw(G) = O(

√k), which can be decided (and a corresponding tree-decomposition can be com-

puted) in time O(2√kn) 28, then by the second property of P , then the solution can be computed

in time O(2√kn). Otherwise, by the Grid theorem, G has a

√k ×√k-grid H as minor. Since

fP (H) = Ω(k) and P is closed under taking minor, then fP (G) = Ω(k).Finally, since k ≤ n, the result follows.

The above theorem has been generalized for larger classes of sparse graphs such as boundedgenus graphs and even graphs excluding some fixed graph as minor.

23A graph is planar if it can be drawn on the sphere without crossing edges.24Neil Robertson, Paul D. Seymour: Graph minors. V. Excluding a planar graph. J. Comb. Theory, Ser. B

41(1): 92-114 (1986)25Ken-ichi Kawarabayashi, Yusuke Kobayashi: Linear min-max relation between the treewidth of H-minor-free

graphs and its largest grid. STACS 2012: 278-28926Julia Chuzhoy, Zihan Tan: Towards Tight(er) Bounds for the Excluded Grid Theorem. SODA 2019: 1445-

146427Erik D. Demaine, MohammadTaghi Hajiaghayi: The Bidimensionality Theory and Its Algorithmic Applica-

tions. Comput. J. 51(3): 292-302 (2008)28e.g., Hans L. Bodlaender, Pal Gronas Drange, Markus S. Dregi, Fedor V. Fomin, Daniel Lokshtanov, Michal

Pilipczuk: A ck n 5-Approximation Algorithm for Treewidth. SIAM J. Comput. 45(2): 317-378 (2016),Hans L. Bodlaender: A linear time algorithm for finding tree-decompositions of small treewidth. STOC 1993:226-234

41

Page 42: Lecture on Graphs and Algorithms (Master 1)Lecture on Graphs and Algorithms (Master 1) Nicolas Nisse Abstract These are lecture notes of the course I gave, at Master 1 level. The main

A third definition of treewidth. For completeness (and to conclude this brief introductionto treewidth), let us give another definition of treewidth. A graph is chordal if it has no inducedcycle of length at least 4 as subgraph. Equivalently, a graph is chordal if it is the intersectiongraph of a family of subtrees of a tree. Given a graph G, let ω(G) be the maximum size of aclique in G. The treewidth of a graph G can be defined as the minimum ω(H) − 1 among allchordal supergraphs H of G. Note that there is a close relationship between tree-decompositionsof a graph G and the clique trees of its chordal supergraphs29.

8.5 Graph Minor theory

To conclude this section, let us try to sketch the main reason why Robertson and Seymourintroduced tree-decompositions and treewidth. Note that there are very nice surveys on thistopic30. Recall that a partial order is called Well Quasi Ordered (WQO) if it admits no infiniteantichain (i.e., no infinite sequence of elements that are pairwise incomparable). The Wagner’sconjecture (1970) asked whether the minor ordering is WQO over the set of graphs. Along a serieof 20 papers (with overall about 500 pages) from 1983 to 2004, Robertson and Seymour answeredthis question (and many fundamental others) through what is now called the Graph Minortheory (interestingly, the order of publication of these papers does not necessarily correspondsto the order of the results).

Theorem 27 (Robertson and Seymour 2004) 31 The minor relationship is WQO.

Before giving a very rough idea of its proof, let us show the algorithmic consequences of theabove theorem. A class of graph G is minor-closed if, for every H G, G ∈ G implies thatH ∈ G. Given a graph class G, let the set of obstructions Obs(G) be the set of minor-minimalgraphs not in G, i.e., the set of graphs H such that H /∈ G and H ′ ∈ G for all H ′ ≺ H.

Corollary 4 Let G be a minor-closed class of graphs. Then Obs(G) is finite.

Proof. Otherwise, by Theorem 27, there would be two graphs G,G′ in Obs(G) such thatG ≺ G′, a contradiction.

As an example, note first that any minor of a planar is also planar. Hence, the class P ofplanar graphs is minor-closed.

Theorem 28 (Wagner 1937) A graph is planar if and only if it has no K5 nor K3,3 (thecomplete bipartite graph with 3 vertices in each part) as minor, i.e., Obs(P) = K5,K3,3.

To understand the importance of Corollary 4, let us do a short detour to vertex-disjointpaths in graphs. Given a graph G = (V,E) and two disjoint subsets X,Y ⊂ V with |X| =|Y | = k, the problem of deciding whether there are k vertex-disjoint paths between X and Y(and compute such paths) can be solved in polynomial-time (e.g., using flow algorithm or theproof of Menger’s theorem). In contrast, given a graph G = (V,E) and two disjoint subsetsX = s1, · · · , sk, Y = t1, · · · , tk ⊂ V with |X| = |Y | = k, the problem of deciding whetherthere are k vertex-disjoint paths P1, · · · , Pk, where Pi is a path between si and ti for all i ≤ k,(and compute such paths) is NP-complete [7]. To see the difference between the two problems,

29Philippe Galinier, Michel Habib, Christophe Paul: Chordal Graphs and Their Clique Graphs. WG 1995:358-371

30See the survey of Lovasz here and the survey of Robertson and Seymour themselves (1985) here.31Neil Robertson, Paul D. Seymour: Graph Minors. XX. Wagner’s conjecture. J. Comb. Theory, Ser. B 92(2):

325-357 (2004)

42

Page 43: Lecture on Graphs and Algorithms (Master 1)Lecture on Graphs and Algorithms (Master 1) Nicolas Nisse Abstract These are lecture notes of the course I gave, at Master 1 level. The main

consider a cycle with vertices (s1, s2, t1, t2) (in this order): clearly, there are 2 vertex-disjointpaths from X = s1, s2 to Y = t1, t2, but 2 vertex-disjoint paths P1 from s1 to t1 and P2

from s2 to t2 do not exist.One of the numerous fundamental contributions of Robertson and Seymour along their

Graph Minor serie is the proof that, when k is fixed, the latter problem (k-linkage), is FPTin k32. This allowed them to show that, given a fixed graph H, the problem that takes ann-node graph G as input and asks whether H G (G admits H as minor) can be solved intime O(n3) where the “big O” hides a constant depending on H (this result has been improvedto an O(n2)-time algorithm since then).

Theorem 29 (Kawarabayashi, Kobayashi and Reed 2012) Let H be a fixed graph. Theproblem that takes an n-node graph G as input and decides if H G can be solved in timeO(n2).

To give an intuition of the relationship between the minor containment problem and the k-linkage problem, let us give the very sketchy following process (whose time-complexity is muchworst than the one announced in previous theorem but still polynomial for fixed H). First,we can “guess” the vertices of G that correspond to vertices of H (by trying the O(n|V (H)|)possibilities). For each choice of |V (H)| vertices in G, then, we have to recover the |E(H)|edges of H as |E(H)| vertex-disjoint paths in G (with sources and terminal the vertices we haveguessed).

Now, we are ready to give the main algorithmic consequence of Robertson and Seymour’stheorem.

Theorem 30 Let G be any minor-closed graph class. The problem that takes a graph G asinput and asks whether G ∈ G is in P .

Proof. The algorithm is as follows. For each H ∈ Obs(G) (there are a finite number of suchgraph by Corollary 4), decide if H G (can be done in polynomial-time by Theorem 29). IfH G for some H ∈ Obs(G) then G /∈ G, else G ∈ G.

Note that previous theorem is only an existential result since it requires the knowledge ofObs(G) for the considered graph class G. Unfortunately, as far as I know, the set of obstructionsis known for very few graph classes. For instance, the full set of obstructions of the class ofgraphs with genus 1 (that can be embedded without crossing edges on a “doughnut”) is stillunknown.

“Proof” of Robertson and Seymour’s theorem. To conclude this section, let us givea very very very sketchy (and probably a bit wrong, sorry) idea of the proof of Theorem 27.Roughly, the guideline is to prove that the minor relationship is WQO in graph classes that aremore and more large.

Theorem 31 (Kruskal 1960) The minor relationship is WQO in the class of trees.

The next step is naturally the class of graphs with bounded treewidth.

Theorem 32 (Robertson and Seymour 1990) 33 The minor relationship is WQO in theclass of graphs with bounded treewidth.

32Neil Robertson, Paul D. Seymour: Graph Minors XIII. The Disjoint Paths Problem. J. Comb. Theory, Ser.B 63(1): 65-110 (1995)

33Neil Robertson, Paul D. Seymour: Graph minors. IV. Tree-width and well-quasi-ordering. J. Comb. Theory,Ser. B 48(2): 227-254 (1990)

43

Page 44: Lecture on Graphs and Algorithms (Master 1)Lecture on Graphs and Algorithms (Master 1) Nicolas Nisse Abstract These are lecture notes of the course I gave, at Master 1 level. The main

Intuitively, let (G1, · · · ) be an infinite sequence of graphs with treewidth at most k, and let(Ti,Xi) be a tree-decomposition of width k of Gi. The sequence (T1, · · · ) is an infinite sequenceof trees and, by Threorem 31, we can extract an infinite sequence (Ti1 Ti2 · · · ). Becausethe graphs (Gi1 , Gi2 , · · · ) have bounded treewidth, the trees (Ti1 , Ti2 , · · · ) can be seen as treeswith labels of bounded length on their vertices. The result follows (after some work).

Next, the case of planar graphs arises.

Theorem 33 (Robertson and Seymour 1986) 34 The minor relationship is WQO in theclass of planar graphs.

Indeed, very intuitively, let us consider an infinite sequence S of planar graphs. If infinitelyof them have bounded treewidth, then the result follows previous theorem. Otherwise, by thegrid Theorem 25, they have arbitrary large grids as minors. Note that, for any planar graph G,there exists a grid Gr such that G Gr. Overall, it is possible to find G,G′ ∈ S such that G′

has a sufficiently large grid Gr as minor such that G Gr. Hence, G Gr G′.Previous result can then be extended to bounded genus graphs. Roughly, a surface has

(orientable) genus at most g if it can be obtained from a sphere by adding to it g handles. Agraph has genus g if it can be embedded without crossing edges on a surface with genus g (planargraphs are graphs with genus 0, graphs with genus ≤ 1 are the ones that can be embedded ona doughnut...). See [1] for more formal definitions.

Theorem 34 (Robertson and Seymour 1990) 35 The minor relationship is WQO in theclass of graphs with bounded genus.

We now can “conclude”. Let (G1, · · · ) be an infinite sequence of graphs. For every k ≥ 2,G1 Gk (since otherwise we are done). Hence, the graphs G2, · · · are all excluding G1 asminor. A key contribution of Robertson and Seymour is the structural characterization of thegraphs excluding a fixed graph H as minor. Namely, given a fixed graph H, they show thatany H-minor free graph (i.e., excluding H as minor) admits a particular decomposition36 thatwe try to sketch below.

Very very very roughly (sorry again), a H-minor free graph G admits a tree-decomposition(T,X ) such that

• for every uv ∈ E(T ), |Xu ∩Xv| ≤ 3 (this bound is actually due to Demaine et al.);

• for every v ∈ V (T ), the bag Xv induces a graph Gv that is obtained from: a graph G′vthat has bounded (in terms of |H|) genus, to which it can be added a bounded (in termsof |H|) number of vortices (subgraphs of bounded (in terms of |H|) “pathwidth” that maybe “glued” along non-contractible cycles of G′v) and then a bounded (in terms of |H|)number of apices can be added (vertices that can be adjacent to any vertex).

The proof of Theorem 27 then follows from Robertson and Seymour’s decomposition andprevious theorems (bounded treewidth, bounded genus...).

34Neil Robertson, Paul D. Seymour: Graph minors. V. Excluding a planar graph. J. Comb. Theory, Ser. B41(1): 92-114 (1986)

35Neil Robertson, Paul D. Seymour: Graph minors. VIII. A kuratowski theorem for general surfaces. J. Comb.Theory, Ser. B 48(2): 255-288 (1990)

36Neil Robertson, Paul D. Seymour: Graph Minors. XVI. Excluding a non-planar graph. J. Comb. Theory,Ser. B 89(1): 43-76 (2003)

44

Page 45: Lecture on Graphs and Algorithms (Master 1)Lecture on Graphs and Algorithms (Master 1) Nicolas Nisse Abstract These are lecture notes of the course I gave, at Master 1 level. The main

References

[1] B. Mohar, C. Thomassen Graphs on Surfaces. Johns Hopkins University Press Books, 2001, ISBN: 978-0-80186-689-0.

[2] A. Bondy, M.S.R. Murty. Graph Theory. Graduate texts in maths, Springer 2008, ISBN 978-1-84628-969-9.

[3] T.H. Cormen, C.E. Leiserson, R.L. Rivest, C. Stein. Introduction to Algorithms. MIT Press 2009, ISBN978-0-262-03384-8.

[4] M. Cygan, F.V. Fomin, L. Kowalik, D. Lokshtanov, D. Marx, Ma. Pilipczuk, Mi. Pilipczuk, S. Saurabh.Parameterized Algorithms. Springer 2015, ISBN 978-3-319-21274-6

[5] R. Diestel: Graph Theory. Graduate texts in mathematics 173, Springer 2012, ISBN 978-3-642-14278-9

[6] F.V. Fomin, D. Kratsch: Exact Exponential Algorithms. Texts in Theoretical Computer Science. An EATCSSeries, Springer 2010, ISBN 978-3-642-16532-0

[7] M.R. Garey, D.S. Johnson: Computers and Intractability: A Guide to the Theory of NP-Completeness W.H. Freeman & Co, 1979, ISBN:0716710447

[8] V. V. Vazirani: Approximation algorithms. Springer 2001, ISBN 978-3-540-65367-7

45