Graph Theory 2018 { EPFL { Lecture Notes. · Graph Theory 2018 { EPFL { Lecture Notes. Lecturer:...

48
Graph Theory 2018 – EPFL – Lecture Notes. Lecturer: D ´ aniel Kor ´ andi May 31, 2018 Acknowledgements: These notes are partially based on the lecture notes of the Graph Theory courses given by Frank de Zeeuw and Andrey Kupavskii. Lecture 1 Introduction 1 Definitions Definition. A graph G =(V,E) consists of a finite set V and a set E of two-element subsets of V . The elements of V are called vertices and the elements of E are called edges. For instance, very formally we can introduce a graph like this: V = {1, 2, 3, 4}, E = {{1, 2}, {3, 4}, {2, 3}, {2, 4}}. In practice we more often think of a drawing like this: 1 2 3 4 Technically, this is what is called a labelled graph, but we often omit the labels. When we say something about an unlabelled graph like , we mean that the statement holds for any labelling of the vertices. Here are two examples of related objects that we do not consider graphs in this course: 1

Transcript of Graph Theory 2018 { EPFL { Lecture Notes. · Graph Theory 2018 { EPFL { Lecture Notes. Lecturer:...

Page 1: Graph Theory 2018 { EPFL { Lecture Notes. · Graph Theory 2018 { EPFL { Lecture Notes. Lecturer: Daniel Kor andi May 31, 2018 Acknowledgements: These notes are partially based on

Graph Theory 2018 – EPFL – Lecture Notes.

Lecturer: Daniel Korandi

May 31, 2018

Acknowledgements: These notes are partially based on the lecture notes of the GraphTheory courses given by Frank de Zeeuw and Andrey Kupavskii.

Lecture 1

Introduction

1 Definitions

Definition. A graph G = (V,E) consists of a finite set V and a set E of two-element subsetsof V . The elements of V are called vertices and the elements of E are called edges.

For instance, very formally we can introduce a graph like this:

V = 1, 2, 3, 4, E = 1, 2, 3, 4, 2, 3, 2, 4.

In practice we more often think of a drawing like this:

1 2

34

Technically, this is what is called a labelled graph, but we often omit the labels. When wesay something about an unlabelled graph like , we mean that the statement holds for anylabelling of the vertices.

Here are two examples of related objects that we do not consider graphs in this course:

1

Page 2: Graph Theory 2018 { EPFL { Lecture Notes. · Graph Theory 2018 { EPFL { Lecture Notes. Lecturer: Daniel Kor andi May 31, 2018 Acknowledgements: These notes are partially based on

The first is a multigraph, which can have multiple edges and loops; the corresponding defini-tion would allow the edge set and the edges to be multisets. The second is a directed graph, inwhich every edge has a direction; in the corresponding definition the edges would be orderedpairs instead of two-element subsets.

Although this course is mostly not about these variants, in some cases it will be morenatural to state our results for directed or multigraphs. In any case, we will not treat infinitegraphs in this course.

Graphs (and their above-mentioned variants) are highly applicable in- and outside math-ematics because they provide a simple way of modeling many concepts involving connec-tions between objects. For example, graphs can model social networks (vertices=people &edges=friendships), computer networks (computers & links), molecules (atoms & bonds) andmany other things. The aim of this course is to study graphs in the abstract sense, and tointroduce the fundamental concepts, tools, tricks and results about them.

Some notation: Given a graph G, we write V (G) for the vertex set, and E(G) for theedge set. For an edge x, y ∈ E(G), we usually write xy, and we consider yx to be the sameedge. If xy ∈ E(G), then we say that x, y ∈ V (G) are adjacent or connected or that they areneighbors. If x ∈ e, then we say that x ∈ V (G) and e ∈ E(G) are incident.

Definition (Subgraphs). Two graphs G,G′ are isomorphic if there is a bijection ϕ : V (G)→V (G′) such that xy ∈ E(G) if and only if ϕ(x)ϕ(y) ∈ E(G′). A graph H is a subgraph of agraph G, denoted H ⊂ G, if there is a graph H ′ isomorphic to H such that V (H ′) ⊂ V (G)and E(H ′) ⊂ E(G).

With this definition we can for instance say that is a subgraph of . As mentionedabove, when we talk about graphs we often omit the labels of the vertices. A more formal wayof doing this is to define an unlabelled graph to be an isomorphism class of labelled graphs.We will be somewhat informal about this distinction, since it rarely leads to confusion.

Definition (Degree). Fix a graph G = (V,E). For v ∈ V , we write

N(v) = w ∈ V : vw ∈ E

for the set of neighbors of v (which does not include v). Then d(v) = |N(v)| is the degreeof v. We write δ(G) for the minimum degree of a vertex in G, and ∆(G) for the maximumdegree.

Definition (Examples). The following are some of the most common types of graphs.

• Paths are the graphs Pn of the form . The graph Pn has n− 1 edges and ndifferent vertices; we say that Pn has length n− 1.

• Cycles are the graphs Cn of the form . The graph Cn has n edges and ndifferent vertices; the length of Cn is defined to be n.

• Complete graphs (or cliques) are the graphs Kn on n vertices in which all vertices areadjacent. The graph Kn has

(n2

)edges. For instance, K4 is .

• The complete bipartite graphs are the graphs Ks,t with a partition V (Ks,t) = X ∪ Ywith |X| = s, |Y | = t, such that every vertex of X is adjacent to every vertex of Y , andthere are no edges inside X or Y . Then Kst has st edges. For example, K2,3 is .

The following are the most common properties of graphs that we will consider.

2

Page 3: Graph Theory 2018 { EPFL { Lecture Notes. · Graph Theory 2018 { EPFL { Lecture Notes. Lecturer: Daniel Kor andi May 31, 2018 Acknowledgements: These notes are partially based on

Definition (Bipartite). A graph G is bipartite if there is a partition V (G) = X ∪ Y suchthat every edge of G has one vertex in X and one in Y ; we call such a partition a bipartition.

Definition (Connected). A graph G is connected if for all x, y ∈ V (G) there is a path in Gfrom x to y (more formally, there is a path Pk which is a subgraph of G and whose endpointsare x and y).A connected component of G is a maximal connected subgraph of G (i.e., a connected subgraphthat is not contained in any larger connected subgraph). The connected components of G forma partition of V (G).

2 Basic Facts

In this section we prove some basic facts about graphs. It is a somewhat arbitrarycollection of statements, but we introduce them here to get used to the terminology and tosee some typical proof techniques.

Proposition 1.1. In any graph G we have∑

v∈V (G)

d(v) = 2|E(G)|.

Proof. We count the number of pairs (v, e) ∈ V (G)×E(G) such that v ∈ e, in two differentways. On the one hand, a vertex v is involved in d(v) such pairs, so the total number of suchpairs is

∑v∈V (G) d(v). On the other hand, every edge is involved in two such pairs, so the

number of pairs must equal 2|E(G)|.

What we used here is a very powerful proof technique in combinatorics, called doublecounting. The lemma itself is sometimes called the “handshake lemma” because it says thatat a party the number of shaken hands is twice the number of handshakes. It has usefulcorollaries, such as the fact that the number of odd-degree vertices in a graph must be even.

Next, we will describe a very important characterization of bipartite graphs. But first,we need two more definitions.

Definition (Walk). A walk is a sequence v1e1v2e2 . . . vk of (not necessarily distinct) verticesvi and edges ei such that ei = vivi+1. A closed walk is a walk with v1 = vk. The length ofthis walk is the number of edges, k − 1.

It is easy to see that paths are exactly walks with no repeating vertices, and cycles areexactly closed walks with no repeating vertices apart from v1 = vk.

Definition (Distance). The distance d(u, v) of two vertices u, v ∈ V (G) is the length of theshortest path (or walk) in G from u to v. (If there is no u-v path in G then d(u, v) =∞.)

Now we are ready to prove the characterization. Note that “contains a cycle” means thatthe graph has a subgraph that is isomorphic to some Cn, and similarly for paths. An “oddcycle” is just a cycle whose length is odd.

Theorem 1.2. A graph is bipartite if and only if it contains no odd cycle.

Proof. To prove the easy direction of the statement, suppose that G is bipartite with bipar-tition V (G) = X ∪ Y , and let v1 · · · vkv1 be a cycle in G with, say, v1 ∈ X. We must havevi ∈ X for all odd i and vi ∈ Y for all even i. Since vk is adjacent to v1, it must be in Y , sok must be even and the cycle is not odd.

Now for the other direction, suppose G has no odd cycles. We may assume that G isconnected. Indeed, otherwise we can apply the same argument to each connected component

3

Page 4: Graph Theory 2018 { EPFL { Lecture Notes. · Graph Theory 2018 { EPFL { Lecture Notes. Lecturer: Daniel Kor andi May 31, 2018 Acknowledgements: These notes are partially based on

Gi of G to get a bipartition Xi ∪ Yi of Gi. Choosing X = ∪iXi and Y = ∪iYi will then givea bipartition of G.

So if v is a fixed vertex, then every other vertex u ∈ V (G) has finite distance from v. Let

X = u : distance of v and u is evenY = u : distance of v and u is odd.

Our aim is to prove that this is a bipartition of G. For this, we need to check that no twovertices in X are adjacent and no two vertices in Y are adjacent.

Suppose for contradiction that some two vertices u1, u2 ∈ X are adjacent, and let e bethe edge u1u2. By construction, there are paths P1 from v to u1 and P2 from u2 to v thatboth have even lengths. But then joining P1, P2 and the edge e gives a closed walk P1eP2

of odd length, so by Claim 1.3 below, G contains an odd cycle, as well, contradiction theassumption. (Note that P1eP2 is not necessarily a cycle because P1 and P2 might intersect!)

We can do the same to show that no two vertices u1, u2 ∈ Y are adjacent: here the pathsP1, P2 will both have odd lengths, so again P1eP2 is a closed odd walk. So X ∪ Y is indeeda bipartition of G.

The proof above is a constructive argument, where we explicitly constructed the objectwe were looking for (and then proved that it satisfies the required properties). Of course, westill need to prove the following lemma to complete the proof. We use an inductive argument.

Claim 1.3. Every closed walk of odd length contains an odd cycle.

Proof. We apply induction on the length k of the walk. Since there is no closed walk oflength 1, the statement is vacuously true for k = 1. We could use this as the base case, butit is also easy to see that the only closed walk of length 3 is the triangle (K3), which itself isan odd cycle.

Now suppose the statement is true for every odd length < k, and let W = v1e1v2 . . . vk+1

be a closed walk of odd length k. Let j be the smallest index such that vi = vj for somei < j. We have two cases. If j − i is even, then deleting the j − i edges ei, . . . , ej−1 from Wyields another closed walk W ′ ⊆ W of odd length. Applying induction on W ′ then gives anodd cycle in W ′ and hence in W .

On the other hand, if j − i is odd (and it cannot be 1, so j − i ≥ 3), then the j − i edgesei, . . . , ej−1 form an odd cycle. Indeed, they form an odd walk without repeated vertices bythe choice of vj. This is what we were looking for.

The next lemma shows that if all degrees of a graph are large, then it must contain along path. The proof is an example of an extremal argument, where we take an object that isextremal with respect to some property, and show that this extremality implies some otherproperty of the object.

Proposition 1.4. A graph G with minimum degree δ(G) contains a path of length at leastδ(G).

Proof. Let v1 · · · vk be a maximal path in G, i.e., a path that cannot be extended. Then anyneighbor of v1 must be on the path, since otherwise we could extend it. Since v1 has at leastδ(G) neighbors, the set v2, . . . , vk must contain at least δ(G) elements. Hence k ≥ δ(G)+1,so the path has length at least δ(G).

Note that in general this bound cannot be improved, because Kδ+1 has minimum degreeδ, but its longest path has length δ. In problem set 1, we will prove an analogous statementfor cycles.

4

Page 5: Graph Theory 2018 { EPFL { Lecture Notes. · Graph Theory 2018 { EPFL { Lecture Notes. Lecturer: Daniel Kor andi May 31, 2018 Acknowledgements: These notes are partially based on

Lecture 2

Basic results. Trees.

1 More basic facts

The following lemma can be helpful when trying to prove certain statements for generalgraphs that are easier to prove for bipartite graphs. The lemma says that you don’t have toremove more than half the edges of a graph to make it bipartite. The proof is an example ofan algorithmic proof, where we prove the existence of an object by giving an algorithm thatconstructs such an object.

Proposition 2.5. Any graph G contains a bipartite subgraph H with |E(H)| ≥ |E(G)|/2.

Proof. We prove the stronger claim that G has a bipartite subgraph H with V (H) = V (G)and dH(v) ≥ dG(v)/2 for all v ∈ V (G). Starting with an arbitrary partition V (G) = X ∪ Y(which need not be a bipartition for G), we apply the following procedure. We refer to Xand Y as “parts”. For any v ∈ V (G), we see if it has more edges to X or to Y ; if it has moreedges that connect it to the part it is in than it has edges to the other part, then we move itto the other part. We repeat this until there are no more vertices v that should be moved.

There are at most |V (G)| consecutive steps in which no vertex is moved, since if none ofthe vertices can be moved, then we are done. When we move a vertex from one part to theother, we increase the number of edges between X and Y (note that a vertex may move backand forth between X and Y , but still the total number of edges between X and Y increasesin every step). It follows that this procedure terminates, since there are only finitely manyedges in the graph. When it has terminated, every vertex in X has at least half its edgesgoing to Y , and similarly every vertex in Y has at least half its edges going to X. Thus thegraph H with V (H) = V (G) and E(H) = xy ∈ E(G) : x ∈ X, y ∈ Y has the claimedproperty that dH(v) ≥ dG(v)/2 for all v ∈ V (G).

We have seen in Proposition 1.4 that it is sometimes useful if our graph has large minimumdegree. The next statement shows that every graph with sufficiently many edges must containa subgraph with large minimum degree. We give an inductive proof, although it could alsobe proved using an algorithmic argument.

Proposition 2.6. Let G be a non-empty graph on n vertices with at least dn edges. Then Gcontains a subgraph H with δ(H) > d.

Proof. First of all, we may assume that d is an integer, for otherwise we could replace d withbdc and apply the same result. So let d be a fixed integer. If d = 0 then we can take H tobe an edge of G (because G is non-empty), so we may further assume d > 0.

We now proceed by induction on n. Note that n ≤ 2d is impossible because such a graphhas at most n(n − 1)/2 < nd edges. Also, for n = 2d + 1 the only graph with nd edges isKn = K2d+1, which has minimum degree 2d, so we can take H = G.

Now suppose n > 2d + 1. If δ(G) > d then we can take H = G. Otherwise, there is avertex v of degree d(v) ≤ d. Let G′ = G− v be the subgraph we obtain from G by deletingv and all the edges touching it. Then G′ has n − 1 vertices and at least nd − d = (n − 1)dedges, so by induction, there is a subgraph H ⊆ G′ ⊆ G such that δ(H) > d.

The following is an easy but important fact. Its proof is extremal.

5

Page 6: Graph Theory 2018 { EPFL { Lecture Notes. · Graph Theory 2018 { EPFL { Lecture Notes. Lecturer: Daniel Kor andi May 31, 2018 Acknowledgements: These notes are partially based on

Proposition 2.7. Every u-v walk W contains a u-v path.

Proof. Let v1v2 . . . vk be a shortest u-v walk in W (more precisely, in the graph defined bythe edges of W ), so u = v1 and v = vk. We claim that this walk is in fact a path. Indeed,if vi = vj for some i < j, then v1v2 . . . vivj+1 . . . vk is also a u-v walk, and it is shorter (hasfewer edges), which is not possible. So the shortest walk has no repeated vertices, i.e., it isa path.

This fact has the useful corollaries that we can replace paths with walks in some of ourdefinitions:

• The distance d(u, v) is equal to the length of the shortest u-v walk.

• A graph is connected if and only if every pair of vertices u, v is connected by a walk.

The latter connectivity property is sometimes easier to check. Also, it clearly implies thatconnectivity is an equivalence relation.

Our last basic result gives a connection between the number of edges and the number ofconnected components in a graph.

Proposition 2.8. If a graph G has n vertices and k edges, then it has at least n− k compo-nents.

Proof. Let us start with the empty graph and add the edges of G to it one-by-one. At thebeginning there are n vertices and no edges, so we have n components. Each added edgetouches at most 2 of the components, and joins these components if they are different (anedge within a component does not affect any components). This means that adding an edgedecreases the number of components by at most 1. Adding k edges therefore decreases thenumber of components by at most k, so after adding all k edges of G, we are left with atleast n− k of them.

Corollary 2.9. Every connected graph on n vertices has at least n− 1 edges.

2 Trees

Definition. A tree is a connected graph without cycles. A forest is a graph without cycles.In a tree or a forest, a vertex of degree one is called a leaf.

Lemma 2.10. Every tree with at least two vertices has a leaf.

Proof. Take a longest path v0v1 . . . vk in the tree (so k ≥ 1, since the tree has at least twovertices). A neighbor of v0 cannot be outside the path, since then the path could be extended.But if v0 were adjacent to vi for some i > 1, then v0v1 · · · viv0 would be a cycle. So the onlyneighbor of v0 is v1, and v0 is a leaf. The same argument shows that vk is also a leaf.

Theorem 2.11. Any tree T on n vertices has n− 1 edges.

Proof. We use induction on the number of vertices. If n = 1, then we have 0 edges. Otherwise,Proposition 2.10 gives a leaf v of T . Let T ′ = T − v be the graph obtained by removing vand its only edge. Then T ′ is connected, since for any x, y ∈ V (T ′) there is a path from x toy in T , and this path cannot pass through v, so it is also a path in T ′. Since T has no cycles,neither does T ′, so T ′ is a tree, on n− 1 vertices. By induction T ′ has n− 2 edges, so, using|E(T ′)| = |E(T )| − 1, we see that T has n− 1 edges.

6

Page 7: Graph Theory 2018 { EPFL { Lecture Notes. · Graph Theory 2018 { EPFL { Lecture Notes. Lecturer: Daniel Kor andi May 31, 2018 Acknowledgements: These notes are partially based on

Theorem 2.12. A graph G is a tree if and only if for all u, v ∈ V (G) there is a unique pathfrom u to v.

Proof. First suppose we have a graph G in which any two vertices are connected by a unique

path. Then G is certainly connected. Moreover, if G contained a cycle v1...vkv1, then v1vk and

v1v2 · · · vk would be two distinct paths between v1 and vk. Hence G is a tree.Suppose G is a tree and u, v ∈ V (G). Since G is connected, there is at least one path from

u to v. Suppose there are two distinct paths P, P ′ from u to v. If these paths only intersectat u and v, we can immediately combine them into a cycle, but in general the paths couldintersect in a complicated way, so we have to be careful. The paths P and P ′ could start outfrom u being the same; let x be the first vertex that they leave at different edges (so theirnext vertices are different). Let y be the first vertex of P after x that is also contained in P ′.Then there is a cycle in G that goes along P from x to y, and then back along P ′ from y tox. This is a contradiction, so there is a unique path from u to v in G.

3 Breadth-first search

Definition. A spanning tree of a graph G is a subgraph T ⊆ G, which is a tree with V (T ) =V (G).

Our aim is to show that

Theorem 2.13. Every connected graph has a spanning tree.

Our proof method is to provide and algorithm called breadth-first search (BFS) that findsa spanning tree (the breadth-first search tree) with some special properties. This algorithmwill even let us answer various natural questions, like determining the distance between twovertices.

The algorithm starts with a vertex r that we refer to as the root of the spanning tree,and it will gradually extend the tree T by examining the edges of G leaving the current T .We use ∂(T ) to denote this set of “leaving” edges. More precisely, given a graph G and asubgraph H ⊂ G, we define

∂(H) = xy ∈ E(G) : x ∈ V (H), y 6∈ V (H)

for the set of edges going from vertices of H to vertices not in H.

BFS Algorithm (given a graph G and a root r ∈ V (G))

(1) Let T be the graph consisting only of r;

(2) Iterate:

(a) If ∂(T ) = ∅, then go to (3);

(b) For all xy ∈ ∂(T ), if T + xy does not contain a cycle, replace T by T + xy;

(3) If |V (T )| = |V (G)|, output T ; else output “disconnected”.

Next time we will prove that this algorithm works, i.e., it finds a spanning tree if G isconnected.

7

Page 8: Graph Theory 2018 { EPFL { Lecture Notes. · Graph Theory 2018 { EPFL { Lecture Notes. Lecturer: Daniel Kor andi May 31, 2018 Acknowledgements: These notes are partially based on

Lecture 3

BFS. Euler tours. Hamilton cycles.

1 Breadth-first search

As it turns out, BFS not only finds a spanning tree of G, but it finds a shortest path fromits root to any other vertex.

Proposition 3.14. If G is a connected graph, then the breadth-first search algorithm finds aspanning tree of G. In fact, a BFS from root r gives a spanning tree T that contains an r-vpath of length d(r, v) for every vertex v.

Proof. The proof is a combination of the following two claims.

Claim 3.15. If d(r, v) = k, then v is added to the BFS tree T in the first k iterations of Step2

Claim 3.16. If v is added to the BFS T in the k’th iteration of Step 2, then T contains anr-v path of length at most k.

Given these claims, we see that if d(v, r) = k, then T contains an r-v path of length atmost k. Of course there is no shorter path in G, so this path has length exactly k, as needed.

Proof of Claim 3.15. We do induction on k. If k = 0, then r = v and the statement is trivial.Otherwise, let us take a shortest r-v path rv1 . . . vk−1v. Then d(r, vk−1) ≤ k − 1 because ofpath rv1 . . . vk−1 (actually d(r, vk−1) = k − 1 can also be proved using the triangle-inequalityfrom problem set 2), so by induction, vk−1 is added in the first k − 1 iterations. If v is alsoadded, then we are done. Otherwise, vk−1v ∈ ∂(T ) in the k’th iteration, so v is added (viavk−1v or some other edge) to T in the k’th iteration.

Proof of Claim 3.15. Again, we do induction on k. If k = 0, then r = v and the statementis trivial. Otherwise, suppose v was added in the k’th iteration via the edge uv. Then uwas added in the k − 1’st iteration at the latest (actually, exactly then), so by induction,T contains an r-u path of length at most k − 1. Adding uv to this path gives an r-v walk(actually path) of length at most k in T . By Proposition 2.7, this walk contains an r-v path,also of length at most k.

Definition. The diameter of a graph G is the largest distance among any pairs of vertices:diam(G) = maxx,y∈V (G) d(x, y). If G is disconnected, then diam(G) =∞.

BFS has a number of applications in providing fairly (or very) efficient algorithms forsolving certain tasks on graphs. For example:

• Find a shortest path from xu to v in G: Run the algorithm with root u to get a treeT . The unique path from u to v in T (which exists by Lemma 2.12) is a shortest path.

• Find the connected components of G: Run the algorithm with some root r. The verticesexplored by BFS are exactly the component of r. If there is an unexplored vertex r′,run BFS again from r′ as a root. Repeat until all vertices are visited. This actuallygives a spanning forest of G.

8

Page 9: Graph Theory 2018 { EPFL { Lecture Notes. · Graph Theory 2018 { EPFL { Lecture Notes. Lecturer: Daniel Kor andi May 31, 2018 Acknowledgements: These notes are partially based on

• Compute diam(G): For each pair of vertices, we can find a shortest path and thus thedistance. Do this for all pairs and take the largest distance.

• Find a shortest cycle in G: For every edge uv, find a shortest path between u and vin G− uv (if it exists), then combine this path with uv to get a cycle. (This will be ashortest cycle through uv.) Compare all these cycles to find the shortest.

• Determine if G is bipartite: Determine the connected components of G. In everycomponent H, select a root r, and partition the vertices into X = x ∈ V (H) :d(r, x) is even and Y = y ∈ V (H) : d(r, y) is odd. Then H is bipartite if and onlyif X and Y have no internal edges (see the proof of Theorem 1.2), and G is bipartite ifand only if every component is bipartite.

Not all of these algorithms are the most efficient, but they are already much better thanbrute force approaches that go over all possible answers. There are all kinds of algorithmsthat do these tasks faster, but in this course, we don’t care too much about efficiency, andwe focus on the graph-theoretical aspects (in particular, proving that the algorithms work).

We should emphasize, though, that for finding shortest paths between two vertices, BFSis the best general algorithm. For example, Dijkstra’s algorithm, a variant of BFS that worksfor graphs with positive edge weights (representing, e.g, the lengths of streets) is directlyused by routing softwares.

2 Euler tours

Definition. A trail is a walk with no repeated edges. A tour is a closed trail (i.e., one thatstarts and ends at the same vertex).

Definition. An Euler (or Eulerian) trail in a (multi)graph G = (V,E) is a trail in G passingthrough every edge (exactly once). An Euler tour is a tour in G passing through every edge.

This notion originates from the “seven bridges of Konigsberg” problem – the oldest prob-lem in graph theory, originally solved by Euler in 1736 – that asked if it was possible to walkthrough all the seven bridges of Konigsberg in one go without crossing any of them twice.

This question can be turned into a graph problem asking for an Euler trail. Euler solvedthe problem by noticing that the existence of Euler trails is closely related to the degreeparities.

Theorem 3.17. A connected (multi)graph has an Eulerian tour if and only if each vertexhas even degree.

The proof of this theorem is based on the following simple lemma.

9

Page 10: Graph Theory 2018 { EPFL { Lecture Notes. · Graph Theory 2018 { EPFL { Lecture Notes. Lecturer: Daniel Kor andi May 31, 2018 Acknowledgements: These notes are partially based on

Lemma 3.18. In a graph where all vertices have even degree, every maximal trail is a closedtrail.

Proof. Let T be a maximal trail. If T is not closed, then T has an odd number of edgesincident to the final vertex v. However, as v has even degree, there is an edge touching vthat is not contained in T . This edge can be used to extend T to a longer trail, contradictingthe maximality of T .

Proof of Theorem 3.17. To see that the condition is necessary, suppose G has an Euleriantour C. If a vertex v was visited k times in the tour C, then each visit used 2 edges incidentto v (one incoming edge and one outgoing edge). Thus, d(v) = 2k, which is even.

To see that the condition is sufficient, let G be a connected graph with even degrees. LetT = e1e2 . . . e` (where ei = (vi−1, vi)) be a longest trail in G. Then it is maximal, of course.According to the Lemma, T is closed, i.e., v0 = v`. G is connected, so if T does not includeall the edges of G then there is an edge e outside of T that touches it, i.e., e = uvi for somevertex vi in T . Since T is closed, we can start walking through it at any vertex. But if westart at vi then we can append the edge e at the end: T ′ = ei+1 . . . e`e1e2 . . . eie is a trail inG which is longer than T , contradicting the fact that T is a longest trail in G. Thus, T mustinclude all the edges of G and so it is an Eulerian tour.

Corollary 3.19. A connected multigraph G has an Euler trail if and only if it has either 0or 2 vertices of odd degree.

Proof. Suppose T is an Euler trail from vertex u to vertex v. If u = v then T is an Euleriantour and so by Theorem 3.17, it follows that all the vertices in G have even degree. If u 6= vthen let us add a new edge e = uv to G. In this new multigraph G∪e, T ∪e is an Eulertour. By Theorem 3.17 we see that all the degrees in G ∪ e are even. This means that inthe original multigraph G, the vertices u, v are the only ones that have odd degree.

Now we prove the other direction of the corollary. If G has no vertices of odd degree thenby Theorem 3.17 it contains an Eulerian tour which is also an Eulerian trail. Suppose nowthat G has 2 vertices u, v of odd degree. Then add a new edge e to G. Now all vertices ofthe resulting multigraph G ∪ e have even degree, so, by Theorem 3.17, it has an Euleriantour C. Removing the edge e from C gives an Eulerian trail of G from u to v.

3 Hamilton cycles

Euler trails are walks that use each edge exactly once. But what if we want to use eachvertex exactly once?

Definition. A Hamilton (or Hamiltonian) cycle in a graph G is a cycle that contains allvertices of G. A Hamilton path in a graph G is a path that contains all vertices of G. Agraph G is Hamiltonian if it contains a Hamilton cycle.

10

Page 11: Graph Theory 2018 { EPFL { Lecture Notes. · Graph Theory 2018 { EPFL { Lecture Notes. Lecturer: Daniel Kor andi May 31, 2018 Acknowledgements: These notes are partially based on

Although the proof of Theorem 3.17 is not really described in an algorithmic way, it canactually be turned into an efficient algorithm. However, no good algorithm is known thatwould find a Hamilton cycle in a graph: nothing that would be much better a brute-forcealgorithm that tries every possible way to visit all vertices in the graph. Deciding if G isHamiltonian is a so-called NP-hard (actually, NP-complete) problem. Loosely speaking, thismeans that an efficient algorithm for this problem could be transformed into an efficientalgorithm for many other problems that are also considered algorithmically difficult.

Definition. The girth of a graph G is the length of the shortest cycle contained in G. Thecircumference is the length of the longest cycle contained in G.

For example, the complete graph Kn for n ≥ 3 has girth 3 and circumference n.We have seen that computing the girth of a graph can be done fairly efficiently using BFS.

But finding the circumference is even more difficult than deciding if a graph is Hamiltonian(because a graph has a Hamilton cycle if and only if its circumference is n).

Another related problem is to find a shortest Hamilton cycle in a graph with weightededges; this is called the travelling salesman problem (TSP) and is one of the most famouscomputationally hard problems, with many real-life applications.

Although we have no general algorithm or recipe for finding Hamilton cycles, we can stillprove some theorems that are useful in certain situations. Our first example is a necessarycondition for Hamiltonicity.

Given a graph G and a set S ⊂ V (G) of vertices, we write G− S for the graph obtainedby removing the vertices of S from G, along with all the edges touching the vertices in S.

Lemma 3.20. If G has a Hamilton cycle, then for all S ⊂ V (G), G − S has at most |S|connected components.

Proof. The Hamilton cycle must visit all the components of G− S (viewed as subgraphs ofG), and to get from one component to another the cycle must pass through a vertex of S.Thus every component is connected to S by two edges of the cycle (and possibly by otheredges not in the cycle). Since every vertex is incident to two edges of the cycle, we have thattwice the number of components is at most twice the number of vertices of S.

This lemma can be useful to show that a graph does not have a Hamilton cycle. Forexample, if in the left-hand graph G below, S consists of the middle two vertices, then G−Shas three connected components, so by Lemma 3.20 the graph has no Hamilton cycle.

On the other hand, it is important to emphasize that the condition in Lemma 3.20 is notsufficient. For example, one can check that the right-hand graph H satisfies the conditionthat for all S ⊂ V (H), H − S has at most |S| components, yet it has no Hamilton cycle. Tosee the latter, observe that for each vertex of degree 2, both incident edges would need tobe in the cycle; but then the middle vertex would be incident to at least three edges of thecycle, which is impossible.

11

Page 12: Graph Theory 2018 { EPFL { Lecture Notes. · Graph Theory 2018 { EPFL { Lecture Notes. Lecturer: Daniel Kor andi May 31, 2018 Acknowledgements: These notes are partially based on

Lecture 4

Hamilton cycles.

1 Sufficient conditions for Hamiltonicity

First, we will show that a graph with many edges must have a Hamilton cycle. Unfor-tunately, there is no chance to get a very good bound on the number of edges sufficientto guarantee a Hamilton cycle, because there are “almost complete” graphs that are notHamiltonian.

Take for instance the graph G consisting of Kn−1 and an additional vertex connected toa single vertex of Kn−1. This graph has

(n−1

2

)+ 1 edges (so only misses n− 2 edges), but it is

not Hamiltonian, because it has a vertex of degree 1. Our next result shows that any graphwith more edges contains a Hamilton cycle.

Theorem 4.21. If G is an n-vertex graph with |E(G)| >(n−1

2

)+ 1 edges, then G contains a

Hamilton cycle.

Proof. We apply induction on n. The statement is clearly true for n = 1, 2, 3, so we assumen > 3.

We claim that G has a vertex v of degree at least n − 2. Indeed, otherwise every vertexhas degree at most n− 3, so

|E(G)| =∑

v d(v)

2≤ n(n− 3)

2<

(n− 1)(n− 2)

2=

(n− 1

2

),

contradicting our assumption.Now let G′ = G− v, so G′ has n− 1 vertices. We distinguish the two cases d(v) = n− 2

and d(v) = n− 1.Suppose d(v) = n− 2. Then

|E(G′)| = |E(G)| − (n− 2) >

(n− 1

2

)+ 1− (n− 2) =

(n− 2

2

)+ 1,

so G′ has a Hamilton cycle C by induction. Since d(v) = n−2 and n > 3, v must be adjacentto two consecutive vertices of this cycle, x and y. Then we can remove the edge xy from Cand replace it by xv and vy to get a Hamilton cycle in G.

Now suppose d(v) = n−1. In this case we only have |E(G′)| >(n−2

2

), so we cannot apply

induction right away. If G′ is complete, then G′ has a Hamilton cycle, and we can add v asin the previous case (in fact, as d(v) = n− 1, v is now adjacent to every vertex of the cycle).

Otherwise, there is an edge xy missing from G′. Let us look at the graph G′ + xy thatwe get by adding xy to G′. Now this graph has more than

(n−2

2

)+ 1 edges, so we can apply

induction to find a Hamilton cycle C in it. If C does not contain xy, then we can again addv as in the previous case. If C does contain xy, then replacing xy with the path xvy in Cgives a Hamilton cycle in G.

As mentioned before, the condition in the theorem above is somewhat weak in the sensethat many graphs that have a Hamilton cycle do not satisfy the condition. The followingsufficient condition does better by looking at the minimum degree instead of the total numberof edges. Note that we have previously seen that every graph G has a cycle of length at leastδ(G)+1. The following theorem says that something much stronger is true when the minimumdegree is at least |V (G)|/2.

12

Page 13: Graph Theory 2018 { EPFL { Lecture Notes. · Graph Theory 2018 { EPFL { Lecture Notes. Lecturer: Daniel Kor andi May 31, 2018 Acknowledgements: These notes are partially based on

Theorem 4.22 (Dirac). Let G be a graph on n ≥ 3 vertices. If δ(G) ≥ n2, then G contains

a Hamilton cycle.

Proof. First observe that G must be connected, because each component contains at leastδ(G) + 1 > n/2 vertices, so G cannot have more than one components.

Take a longest path P = v1v2 . . . vk in G. By maximality, all neighbors of v1 and vk arein the path. Let us say that an edge vivi+1 is type-1 if vi+1 ∈ N(v1), and let us say that itis type-2 if vi ∈ N(vk). As δ(G) ≥ n/2, we have at least n/2 type-1 and n/2 type-2 edgesin P . But P has at most n − 1 edges, so some edge vjvj+1 is both type-1 and type-2, i.e.,v1vj+1 and vjvk are edges of G. Then C = P − vjvj+1 + v1vj+1 + vjvk = vj . . . v1vj+1 . . . vkviis a cycle.

In fact, C is a Hamilton cycle. Indeed, suppose not all vertices are contained in C. SinceG is connected, there must be an edge uvi where u /∈ C. Then there is a path that goes fromu to vi and then all around the cycle C to a neighbor of vi. This path contains k+ 1 vertices,contradicting the maximality of P .

This theorem is again best possible, in the sense that a weaker bound on the minimumdegree would not imply a Hamilton cycle. Take for instance the graph G consisting of twocopies of Kk sharing a single vertex. This graph has n = 2k−1 vertices and minimum degreeδ(G) = k − 1 = n−1

2, but no Hamilton cycle, because deleting the shared vertex creates two

components, contradicting Lemma 3.20.It is easy to check that the proof of Dirac’s theorem works for the following strengthening,

as well:

Theorem 4.23 (Ore). Let G be a graph on n ≥ 3 vertices. If d(u) + d(v) ≥ n for anynon-adjacent vertices u and v, then G contains a Hamilton cycle.

Using this theorem, one can also obtain a short proof of Theorem 4.21 (see problem set),so one can think of Ore’s theorem as a common generalization of Theorems 4.21 and 4.22.

We will give one more sufficient condition, that is not a corollary of Ore’s theorem. Weneed the following definition.

Definition. Let G be a graph. A vertex set I ⊆ V (G) is called independent in G if no twovertices of I are connected by an edge of G. The independence number α(G) is the size ofthe largest independent set in G.

For example, α(Kn) = 1, α(Kn,m) = max(n,m), and the independence number of theempty graph on n vertices is n.

Theorem 4.24. Let G be a graph on n ≥ 3 vertices. If G has at least α(G) vertices of degreen− 1, then it contains a Hamilton cycle.

Proof. Let k = α(G), and let us take a longest cycle C in G. We will prove that C is aHamilton cycle. So suppose that C is not Hamiltonian, and let v be any vertex not containedin the cycle. Then:

• v is not adjacent to both of any two consecutive vertices x, y in C.

Indeed, otherwise we could replace the edge xy in C with the path xvy to get a longer cycle(see figure on the right). In particular, this observation means that every vertex of degreen− 1 is in the cycle.

So let v1, . . . , vk ∈ C be k of the vertices of degree n − 1, and for each i = 1, . . . , k, letui be the vertex immediately following vi on C in the clockwise direction. The observationabove implies that no ui is a neighbor of v, in particular, the ui are all different from the vi.

13

Page 14: Graph Theory 2018 { EPFL { Lecture Notes. · Graph Theory 2018 { EPFL { Lecture Notes. Lecturer: Daniel Kor andi May 31, 2018 Acknowledgements: These notes are partially based on

Now the set v, u1, . . . , uk has size k + 1 > α(G), so by assumption, it cannot be inde-pendent. G therefore contains an edge uiuj. But then we can remove the edges viui and vjujfrom C and replace them by the edges uiuj, viv and vvj (see figure on the left). Again, weget a longer cycle, and this contradiction shows that C must contain all vertices of G.

uivi

ujvj

v

yx

v

2 Covering the vertices with multiple paths

Not every graph has a Hamilton path. For example, if G has k components, then wesurely need at least k paths to visit all the vertices of G, and even that is not necessarilypossible. The next result shows that α(G) paths are always enough to cover all vertices of G

Theorem 4.25. Every graph G contains a set of at most α(G) vertex-disjoint paths (i.e.paths that share no vertex in common) that together contain all vertices of G.

Proof. We proceed by induction on α(G). If α(G) = 1 then G is a complete graph, so it hasa Hamilton path. So suppose α(G) > 1, and let P = v1 . . . vk be a maximal path in G. Ourplan is to delete this path and its vertices from G and apply the induction hypothesis to theremaining graph G′ = G− v1, . . . , vk.

For this we just need to observe that α(G′) < α(G). Indeed, let X be an independent setin G′ of size α(G′). As P is maximal, all neighbors of v1 are in P , so in particular, v1 is notadjacent to any vertex of G′. But then X ∪v1 is an independent set of size α(G′) + 1 in G.

Hence we can apply induction to G′, and get a set of at most α(G′) disjoint paths thatcover all vertices of G′. Together with P , this gives a collection of at most α(G) disjointpaths that cover all vertices of G.

3 Tournaments

Definition. A tournament is a directed graph that has exactly one (oriented) edge betweenany two vertices.

For example, if we take a complete graph and give each edge an orientation then we geta tournament. We use u→ v to denote that there is an edge uv directed from u to v. Whatis the longest directed path in such a graph?

Theorem 4.26. Every tournament contains a directed Hamilton path.

Proof. We do induction on the number of vertices n. For n = 2, there is nothing to prove,since one can take the only edge of the tournament as the Hamilton path. Now supposen > 2, and let v be a vertex of T . By induction, T − v has a Hamilton path P = v1v2 . . . vn.If v → v1 or vn → v, then vv1v2 . . . vn or v1v2 . . . vnv is a Hamilton path in T . So assumev1 → v and v → vn. But then there must be a vertex vi with 1 ≤ i ≤ n− 1, such that vi → vand v → vi+1, so v1v2 . . . vivvi+1vi+2 . . . vn is a Hamilton path in T .

14

Page 15: Graph Theory 2018 { EPFL { Lecture Notes. · Graph Theory 2018 { EPFL { Lecture Notes. Lecturer: Daniel Kor andi May 31, 2018 Acknowledgements: These notes are partially based on

Of course, not every tournament contains a directed Hamilton cycle. In fact, there is atournament that does not contain any cycle, whatsoever: the so-called transitive tournamenton vertex set 1, . . . , n where each edge is oriented from the smaller endpoint to the largerone. But can we find conditions for the existence of a Hamilton cycle?

A first guess might be that it is enough if every vertex has both an incoming and anoutgoing edge (this is clearly required). But this is not sufficient:

There is, however, a fairly simple necessary and sufficient condition.

Definition. A directed graph is strongly connected if for any two vertices u and v, there isa directed path from u to v (and vice versa).

Theorem 4.27. A tournament T has a Hamilton cycle if and only if it is strongly connected.

Proof. If T is Hamiltonian, then it is clearly strongly connected: for any u and v the Hamiltoncycle contains a path from u to v.

Now, suppose T is not Hamiltonian. Let C be a longest directed cycle in T and take av /∈ C. If C has 2 consecutive vertices u, u′ such that u → v and v → u′, then there is alonger cycle on the vertex set C ∪ v:

uu′

v

C

Otherwise all edges between v and C go in only one direction. By our assumption on C,this must hold for all v /∈ C. Let A be the set of v /∈ C such that edges go from v to C, andlet B be the set of v /∈ C such that edges go from C to v. If one of A or B is empty, thenT cannot be strongly connected. For example, if B is empty then there is no path from anyvertex of C to any vertex of A.

So, suppose both of A and B are nonempty. If there was an edge oriented from somevertex b ∈ B to a vertex a ∈ A then we could extend C, contradicting maximality (we couldreplace any edge x→ y in C with the path x→ b→ a→ y). So all edges between A and Bare directed from A towards B, but then there is no path from any vertex in B to any vertexin A, so again T is not strongly connected.

C

A B

Note that no such description for Hamiltonicity is known for graphs. As mentioned earlier,it is algorithmically hard to decide whether or not a given graph contains a Hamilton cycle.For tournaments this is not the case. For example, one can turn the above proof into arelatively fast algorithm. In some sense, this shows that tournaments are simpler structuresthan graphs.

15

Page 16: Graph Theory 2018 { EPFL { Lecture Notes. · Graph Theory 2018 { EPFL { Lecture Notes. Lecturer: Daniel Kor andi May 31, 2018 Acknowledgements: These notes are partially based on

Lecture 5

Planar graphs.

1 Drawings of graphs

We have so far only considered abstract graphs, although we often used pictures to il-lustrate the graph. In this lecture, we prove some facts about pictures of graphs and theirproperties. To set this on a firm footing, we give a formal definition of what we mean by“picture”, although in most of the lecture we will be less formal.

Definition. A drawing of a graph G consists of an injective map f : V (G) → R2, anda curve γxy (the image of an injective continuous map [0, 1] → R2) from x to y for everyxy ∈ E(G), such that f(z) 6∈ γxy for any vertex z 6= x, y. A drawing is planar if the curvesγxy do not intersect each other except possibly at endpoints.

Definition. A graph is planar if it has a planar drawing.

For example, the graphs K4 and K2,3 are planar graphs.To show that a graph is planar, we only have to supply a planar drawing. It is often a

little harder to show that a graph is not planar.

Proposition 5.28. The graph K5 is not planar.

Proof. The graph contains a K3, which can basically be drawn in only one way. If in adrawing the fourth vertex is inside this K3 and the fifth is outside, then the edge betweenthem must cross the K3, which means that the drawing is not planar. If both vertices areinside the K3, then the three edges of one vertex divide the inside of K3 into three regions.The other vertex must then be in one of these regions, and one vertex of K3 is outside thisregion, so again, the edge between these two vertices crosses the boundary of the region. Asimilar argument applies when both vertices are outside the K3.

Note that this proof heavily relied on the fact that an edge connecting a vertex inside ofK3 (or any other cycle) to a vertex outside must cross the K3 (or cycle). This is a highly non-trivial statement that depends on a strong topological theorem called the Jordan CurveTheorem, that states that every non-self-intersecting closed curve in R2 divides R2 into aninside and an outside, and any path between a point inside and a point outside must passthrough the closed curve. We remark that this theorem is specific to the plane: it is notalways true in some other surfaces, for example, on a torus.

The Jordan Curve Theorem is well beyond the scope of this course. To avoid using suchheavy machinery, we could replace continuous curves with polygonal paths in the definitionof drawings, where a polygonal path is a special curve, whose image is a union of finitelymany segments. The Jordan Curve Theorem is much easier to prove for such paths.

Nevertheless, many technicalities arise when adding edges to drawings, even if we usepolygonal paths, but we are going to ignore these for clarity. Therefore, our proofs concern-ing planarity will sometimes appeal to intuition, hence they will not always be completelyrigorous.

16

Page 17: Graph Theory 2018 { EPFL { Lecture Notes. · Graph Theory 2018 { EPFL { Lecture Notes. Lecturer: Daniel Kor andi May 31, 2018 Acknowledgements: These notes are partially based on

2 Euler’s formula

One important property that distinguishes planar drawings from general graph drawingsis that plane drawings have faces.

Definition. A face of a planar drawing D of a graph G is a maximal connected set in R2

after the vertices and edges of D are removed.

Every planar drawing has an outer face, which is the unique unbounded face in thecomplement of the drawing. We think of the boundary of a face as the closed walk around it.So if an edge only bounds one face, then it appears in the boundary walk twice. (Actually, ifthe graph is disconnected, then the boundary of some faces will not be one closed walk, buta union of closed walks.)

Note that the faces of a drawing are usually not determined by the graph, i.e., differentdrawings might have different boundary walks. However, the following theorem shows thatthe number of faces is always the same.

Theorem 5.29 (Euler’s formula, 1752). Let D be a plane drawing of a connected planargraph with n vertices, e edges and f faces. Then

n− e+ f = 2.

Proof. We use induction on e. Since the graph is connected, we have e ≥ n − 1, so we canstart with the base case e = n − 1. In that case, G contains no cycles (it is a tree), so anyplanar drawing has only one face and we have f = 1. Then

n− e+ f = n− (n− 1) + 1 = 2.

Now suppose e ≥ n. Then G contains a cycle C. Let xy ∈ E(C) be an edge of this cycle.The graph G \ xy is connected, and erasing this edge from D gives a planar drawing D′ ofG− e with n′ vertices, e′ edges and f ′ faces. Clearly, n′ = n and e′ = e− 1.

Moreover, by the Jordan Curve Theorem, there is no face both inside and outside C, soxy is on the boundary of two different faces. Removing xy merges these two faces, and doesnot affect any other faces, so f ′ = f − 1.

Applying induction to D′, we get

2 = n′ − e′ + f ′ = n− (e− 1) + (f − 1) = n− e+ f,

as needed.

As we mentioned before, this means that the number of faces is the same in any planedrawing of a connected planar graph, namely f = 2 + e − n. Euler’s formula also has theimportant consequence that a planar graph cannot be too dense.

Proposition 5.30. Every planar graph G on n ≥ 3 vertices has at most 3n− 6 edges. If Gis also bipartite, then it has at most 2n− 4 edges.

Proof. We may assume that G is connected: otherwise we repeatedly add edges betweendifferent components. This does not change planarity, so if the bound holds for this graph,it will also hold for the original with fewer edges.

Now in a drawing of a connected graph, every face F is bounded by a closed walk; let`F be the length of this walk. As we have observed before, each edge of G is either on theboundary of two faces, or it appears twice in the boundary walk of the one face. Either way,

17

Page 18: Graph Theory 2018 { EPFL { Lecture Notes. · Graph Theory 2018 { EPFL { Lecture Notes. Lecturer: Daniel Kor andi May 31, 2018 Acknowledgements: These notes are partially based on

each edge is counted twice in the sum of the `F . On the other hand, we have `F ≥ 3 for everyface F because G is connected on at least 3 vertices. Hence,

3f ≤∑F face

`F = 2e.

G is connected, so we can apply Euler’s formula. Together with f ≤ 2e/3, it gives

2 = n− e+ f ≤ n− e+ 2e/3 = n− e/3,

which rearranges to e ≤ 3n− 6, as needed.If G is also bipartite, then `F cannot be odd, so `F ≥ 4. The same argument then implies

f ≤ e/2, and plugging this in Euler’s formula gives e ≤ 2n− 4.

This result gives us easy to check necessary conditions for a graph to be planar, e.g., amuch simpler proof of Proposition 5.28.

Corollary 5.31. K5 and K3,3 are not planar.

Proof. K5 has 5 vertices and 10 edges, but 10 > 3 · 5 − 6 = 9, so by Proposition 5.30, itcannot be planar.

Similarly, K3,3 is bipartite, with 6 vertices and 9 edges, but 9 > 2·6−4 = 8, so Proposition5.30 shows it is not planar.

If a graph H is a subgraph of a graph G and H is not planar, then G is also not planar,since a planar drawing of G would give a planar drawing of H. A stronger version of this isthe following. Call a graph H ′ a subdivision of H if it can be obtained from H by repeatedlyreplacing an edge xy by a path xzy for some new vertex z (informally, we simply place thenew vertex z somewhere on top of the edge xy, subdividing it into two edges xz and zy). Itis easy to see that a subdividion of H is planar if and only if H is planar; the new verticesdo not have any effect on whether ot not we can draw the graph without crossing edges.

So if a graph contains a subdivision of K5 or K3,3, then it is not planar. Amazingly, theconverse is also true. If the graph is not planar, then it contains a K5 or K3,3-subdivision:

Theorem 5.32 (Kuratowski). A graph is planar if and only if it does not contain a subdi-vision of K5 or K3,3.

So in some sense K5- and K3,3-subdivisions are the only “obstructions” for planarity. Notethat it states an equivalence between a topological statement (the graph having a planardrawing) and a combinatorial statement (the graph not containing a certain subdivision).The proof of this theorem is fairly hard and we will not include it in this course.

3 Coloring planar graphs

In 1852, Francis Guthrie asked the following question: How many colors are needed topaint the countries of a political map so that adjacent countries get different colors? In fact,he conjectured that four colors are always enough.

This problem can be represented by a planar graph if we place a vertex inside each country,and connect two vertices by an edge if they share a piece of their border.

Definition. A proper vertex coloring of a graph G is a map c : V (G)→ X for some set ofcolors X, such that c(u) 6= c(v) whenever uv ∈ E(G).

The chromatic number χ(G) is the minimum size such a set X, i.e., it is the minimumnumber of colors that the vertices of G can be properly colored with.

18

Page 19: Graph Theory 2018 { EPFL { Lecture Notes. · Graph Theory 2018 { EPFL { Lecture Notes. Lecturer: Daniel Kor andi May 31, 2018 Acknowledgements: These notes are partially based on

Guthrie’s conjecture can then be stated in terms of the chromatic number of planargraphs. After many failed and partially successful attempts, the conjecture was proved 120years later by Appel and Haken, with heavy computer assistance.

Theorem 5.33 (Four color theorem – Appel-Haken, 1976). For every planar G, χ(G) ≤ 4.

Even today, there is no proof known for this theorem that would be feasible to do by hand(the simplest proofs still involve checking over 600 cases). We will instead prove χ(G) ≤ 6first, and then improve it to χ(G) ≤ 5 at the next lecture.

Theorem 5.34. For every planar graph G, χ(G) ≤ 6.

Proof. We proceed by induction on the number of vertices n. For n ≤ 6, there is nothing todo, we can always color the vertices with different colors. Let n ≥ 7.

Claim 5.35. If G is planar, then it has a vertex of degree at most five.

Proof. Suppose not. Then every vertex has degree at least 6, so the number of edges in G isat least 1

2

∑d(v) ≥ 3n. But according to Proposition 5.30, a planar graph can have at most

3n− 6, which is a contradiction.

So let v be a vertex of degree at most 5. By induction, G− v can be (properly) 6-colored.In this coloring, the neighbors of v use at most 5 colors, so we can extend this to a 6-coloringof G by giving v a color not used by its neighbors.

19

Page 20: Graph Theory 2018 { EPFL { Lecture Notes. · Graph Theory 2018 { EPFL { Lecture Notes. Lecturer: Daniel Kor andi May 31, 2018 Acknowledgements: These notes are partially based on

Lecture 6

Coloring.

1 Coloring planar graphs

Theorem 6.36 (Five color theorem – Heawood, 1890). If G is planar, then χ(G) ≤ 5.

Proof. We use induction on the number of vertices n. As before, n ≤ 5 is clear. By Claim5.35, there is a vertex v ∈ V (G) of degree at most five, so by induction, we can color G− vwith five colors. If this coloring uses at most four colors on N(v), then we can color v withthe fifth color and we are done. Thus we can assume that v has five neighbors x1, . . . , x5,and that xi has color i.

Now fix a planar drawing of G. We can assume that the edges vx1, . . . , vx5 leave v in thatorder when we go around v in the clockwise direction (say). We call a path in G an ij-pathif all its vertices have color i or j.

Suppose that there is no 13-path from x1 to x3. Let R be the set of vertices that arereachable from x1 by a 13-path. By assumption, x3 is not in R. So let us swap the colors 1and 3 among the vertices in R: This gives a proper coloring, and it makes both x1 and x3

colored with 3. Then coloring v with 1 gives a 5-coloring of G.Now suppose that there is a 13-path from x1 to x3; together with v this path forms a

cycle C, all of whose vertices are colored with 1 or 3 (or uncolored in the case of v). Let Sbe the set of vertices reachable by 24-paths from x2. Then the cycle C separates S from x4

(here we use the Jordan Curve Theorem), so x4 is not in S. Thus we can swap colors 2 and4 in S, and then color v with 2.

2 Vertex coloring

Recall the we call a graph (properly) k-colorable if its vertices can be colored with kcolors in such a way that no two adjacent vertices get the same color, and that the chromaticnumber χ(G) is the minimum k such that G is k-colorable.

So far we have looked at the chromatic number of planar graphs, but it also makes senseto study the concept for general graphs. Actually, many real-life problems may be interpretedas graph coloring problems. Here is one example from scheduling:

Example. The students at a certain university have annual examinations in all the coursesthey take. Naturally, examinations in different courses cannot be held concurrently if thecourses have students in common. How can all the examinations be organized in as fewparallel sessions as possible? To find a schedule, consider the graph G whose vertex setis the set of all courses, two courses being joined by an edge if they give rise to a conflict.Clearly, independent sets of G correspond to conflict-free groups of courses. Thus, the requiredminimum number of parallel sessions is the chromatic number of G.

We first collect some easy facts about the chromatic number.

Definition. The complement of a graph G is the graph G with vertex set V (G) = V (G) andedge set E(G) = xy : x, y ∈ V (G), xy 6∈ E(G).The clique number ω(G) is the size of the largest complete subgraph (clique) of G. So ω(G) =α(G).

20

Page 21: Graph Theory 2018 { EPFL { Lecture Notes. · Graph Theory 2018 { EPFL { Lecture Notes. Lecturer: Daniel Kor andi May 31, 2018 Acknowledgements: These notes are partially based on

Fact 6.37. 1. χ(Ks) = s

2. G is bipartite if and only if χ(G) ≤ 2

3. If H is a subgraph of G, then χ(H) ≤ χ(G)

4. χ(G) ≥ ω(G) for every graph G.

Proof. 1. and 2. follow from the definition. For 3., we just need to notice that every propercoloring of G provides a coloring of H. 4. is then a combination of 1. and 3.

So ω(G) is a trivial lower bound on the chromatic number, but it is not necessarily tight:

Example. The following graph G satisfies χ(G) = 4 and ω(G) = 3.

G =

A k-coloring can be thought of splitting the vertices into k independent sets. This readilyimplies the following lower bound on χ(G).

Lemma 6.38. For every graph G, we have χ(G) ≥ |V (G)|α(G)

.

Proof. Given a coloring with χ(G) colors, the color classes (label them V1, . . . , Vχ(G)) areindependent sets, and thus have size at most α(G). Hence we have

|V (G)| =χ(G)∑i=1

|Vi| ≤χ(G)∑i=1

α(G) = χ(G)α(G).

Claim 6.39. For any two graphs G1 and G2 on the same vertex set V , χ(G1 ∪ G2) ≤χ(G1)χ(G2).

Proof. For both i = 1, 2, let ki = χ(Gi) and take a ki-coloring ci : V → [ki] of Gi. (Here[n] denotes the set 1, . . . , n.) We will color the vertices in V with elements of the set[k1]× [k2]. Indeed, c(v) = (c1(v), c2(v)) gives a proper k1k2-coloring of G = G1 ∪G2, becauseif two vertices u, v are adjacent in G, then they are also adjacent in some Gi, hence the i’thcoordinate of their colors will differ. So χ(G) ≤ k1k2.

Further simple bounds on the chromatic number can be found in the problem set.

Let G = (V,E) be a graph. We say that G is d-degenerate if every subgraph of G has avertex of degree less than or equal to d. The following proposition connects the degeneracyof G and the chromatic number of G. The six color theorem was in fact a special case of thislemma.

Lemma 6.40. If G is d-degenerate, then χ(G) ≤ d+ 1.

Proof. We do induction on the number of vertices. The statement is clearly true for all Gwith at most d + 1 vertices. For larger graphs, pick a vertex v of degree ≤ d in G. Thegraph G− v is d-degenerate (because every subgraph of G− v is a subgraph of G), so it canbe (d+ 1)-colored. Then color v into the color that does not appear among the colors of itsneighbors. This gives a proper coloring of G.

21

Page 22: Graph Theory 2018 { EPFL { Lecture Notes. · Graph Theory 2018 { EPFL { Lecture Notes. Lecturer: Daniel Kor andi May 31, 2018 Acknowledgements: These notes are partially based on

Corollary 6.41. χ(G) ≤ ∆(G) + 1 for every graph G.

Proof. G is clearly ∆(G)-degenerate.

This corollary is tight for cliques and odd cycles. Interestingly, those are basically theonly examples, as shown by the following theorem.

Theorem 6.42 (Brooks, 1941). Let G be a connected graph that is not isomorphic to Ks orC2k+1 for any s or k. Then χ(G) ≤ ∆(G).

We will not prove this theorem.

3 Edge coloring

Definition. A proper edge coloring of a graph G is a map c : E(G) → X for some setof colors X, such that c(e) 6= c(e′) whenever e, e′ are distinct edges that share a vertex.The edge-chromatic number χ′(G) of G is the minimum size of such a set X, i.e., it is theminimum number k such that the G can be (properly) k-edge-colored.

Example.

• χ′(K3) = 3

• χ′(C4) = 2

• χ′(K4) = 3

• The picture on the right is an edge col-oring of the Petersen graph with fourcolors. It is not difficult to see that itsedge chromatic number is equal to 4.

Definition. A matching M is a set of vertex-disjoint edges, i.e., a set of edges such that notwo of them share an endvertex.

Each color class is a set is a matching, so an edge coloring is a partition of the edges intomatchings.

Lemma 6.43. For any graph G with at least one edge we have ∆(G) ≤ χ′(G) ≤ 2∆(G)− 1.

Proof. There is vertex of degree ∆(G), and an edge coloring must give different colors toeach of the ∆(G) edges at that vertex. This implies χ′(G) ≥ ∆(G).

The upper bound follows by a proof similar to the proof of Lemma 6.40: We can doinduction on the number of edges. So delete an edge e, and take a (2∆(G)− 1)-edge-coloringof G− e. Since an edge shares a vertex with at most 2(∆(G)− 1) edges, there must be a freecolor left for e.

However, this simple upper bound can be significantly improved. This is shown by thefollowing theorem, which tells us that any graph G has edge-chromatic number either ∆(G)or ∆(G) + 1. Both are possible, since even cycles have χe(G) = ∆(G) and odd cycles haveχe(G) = ∆(G) + 1. However, the algorithm in the proof still does not always give the exactnumber, and in fact it is NP-hard to determine which of the two values is the edge-chromaticnumber of a given graph.

22

Page 23: Graph Theory 2018 { EPFL { Lecture Notes. · Graph Theory 2018 { EPFL { Lecture Notes. Lecturer: Daniel Kor andi May 31, 2018 Acknowledgements: These notes are partially based on

Theorem 6.44 (Vizing, 1964). For every graph G we have χ′(G) = ∆ or ∆(G) + 1.

Proof. We only need to show χ′(G) ≤ ∆(G) + 1. To prove this, we use induction on thenumber of edges. The statement clearly holds for a graph without edges.

Given an edge xy ∈ E(G), we describe an algorithm that, given an edge coloring of G−xywith at most ∆(G) + 1 colors, produces an edge coloring of G with this many colors. But tofind a color for xy, the algorithm may have to change the colors of other edges.

So take a coloring of G− xy. As there are more than ∆(G) available colors, every vertexhas at least one color missing from the edges touching it. We say that a vertex v is c-free, ifno edge incident to v has color c.

Now let us build a fan of edges around x as follows. Take the edge xy, and let y0 = y.We know that y0 is c1-free for some color c1. Now let xy1 be an edge of color c1, if such anedge exists. Then y1 is c2-free for some color c2.

Continue similarly: if there is an edge at x of color ci that we have not looked at, let xyibe this edge, and let ci+1 be a color missing at yi. We repeat this process until we can; letxyk be the last edge we added. There are two possible reasons for getting stuck: either thereis no edge at x of color ck+1, or this edge already appeared at some previous xyi.

Case 1. x is ck+1-free.In this case we can just “rotate” the colors around x: Define the new color of xyi to be

ci+1 for every i = 0, . . . , k (keeping the colors of all other edges). This does not create anyissue with any yi, because it had been ci+1-free. There is no problem at x either, because theonly new color introduced is ck+1. Hence this is a proper coloring of G (including the edgexy = xy0).

Case 2. x is not ck+1-free.As noted above, the maximality of k implies that some edge xyi is ck+1-colored, so by

definition ck+1 = ci. Let us just call this color c, and let d be a color such that x is d-free.Now let P be a maximal path starting at x that only uses the colors c and d. Actually,

since every vertex touches at most one c-colored and one d-colored edge, and x is d-free, thereis a unique such maximal path P = xyi . . . z for some vertex z. Let us swap the colors cand d along the path. The same observation shows that this is still a proper edge-coloring ofG− e. We again distinguish two cases.

Case 2/A. z = yi−1.Note that yi−1 was c-free, so the last edge of P must have had color d. After swapping,

yi−1 is no longer c-free, but it is now d-free. However, the edge xyi has color d, as well, sothe edges xyi satisfy the required properties with ci = d now. As x is now c-free, we arriveat a situation covered by Case 1, which gives a proper coloring of G (by rotating the colors,i.e., coloring each xyj with color cj+1).

Case 2/B. z 6= yi−1.In this case, yi−1 remains c-free, and x becomes c-free, as well. This means that we can

rotate the colors on the first i edges only to get a proper edge coloring: recolor xyj with thecolor cj+1 for every j = 0, . . . , i− 1, and leave the color of other edges the same as what wehad after swapping c and d along P . By the same arguments as before, every edge is colored,but no two touching edges get the same color.

23

Page 24: Graph Theory 2018 { EPFL { Lecture Notes. · Graph Theory 2018 { EPFL { Lecture Notes. Lecturer: Daniel Kor andi May 31, 2018 Acknowledgements: These notes are partially based on

Lecture 7

Matchings.

Recall that a matching M is a set of vertex-disjoint edges. A perfect matching M ina graph G is a matching that touches every vertex of G. In other words, it is a 1-regularsubgraph of G (recall that a graph is k-regular if all degrees equal k).

1 Stable matchings

Suppose that you have n students that want to do their internships in n companies. Eachhave sent their applications to all the companies. Each student and each company has theirlist of preferences, and we want to pair up the students with the companies so that thisassignment is stable in the following sense: there is no student and company that would bothprefer to work with each other rather than their assigned pairs.

More formally, consider a bipartite graph G with parts A, B, where |A| = |B| = n, andin which each vertex has a (strict) order of preferences for the vertices of the other part. Wesay that a perfect matching is stable, if there is no pair a ∈ A, b ∈ B, such that both of themwould prefer the other to the vertex they are currently matched to.

Below we present an algorithm of Gale and Shapley, which allows to construct such astable matching.

The Gale-Shapley Algorithm to find a stable matching M in a complete bipartitegraph G = (A ∪B,E) with |A| = |B|

(1) Set M = ∅;

(2) Iterate:

(a) Take an unmatched vertex a ∈ A and let b ∈ B be the vertex that a prefersamong the ones a has not tried yet.

(b) a “proposes” to b: If b is unmatched or b is matched to a′, but prefers a over a′,then “accept” a and “reject” a′: put M := M − a′b+ ab. Otherwise, “reject”:leave M unchanged;

(c) If there is no more unmatched vertices in A that have someone left on the list,then go to (3);

(3) Return M .

Proposition 7.45. The matching M that the algorithm outputs is stable.

Proof. First we show that M is perfect. Indeed, if there is a pair of vertices a ∈ A, b ∈ B,such that both are not in the matching, then a must have proposed to b at some point.However, if a vertex b ∈ B is in M at some step of the algorithm, then it stays in M .

Next, we show that the matching is stable. Assume that ab /∈M. Upon completion of thealgorithm, it is not possible for both a and b to prefer each other over their current match.If a prefers b to its match, then a must have proposed to b before its current match. If baccepted its proposal, but is matched to another vertex at the end, then b prefers the currentmatch of b over a. If b rejected the proposal of a, then b was already matched to a vertexthat is better for b.

24

Page 25: Graph Theory 2018 { EPFL { Lecture Notes. · Graph Theory 2018 { EPFL { Lecture Notes. Lecturer: Daniel Kor andi May 31, 2018 Acknowledgements: These notes are partially based on

2 Maximum matchings

The previous problem was about perfect matchings in a complete bipartite graph. Butnot every graph has a perfect matching. So how can we find a largest or maximum matching?(Not to be confused with a maximal matching, which just means that it cannot be extended,i.e., no larger matching contains it as a subgraph.) How can we even tell if a graph has aperfect matching? How can we check if a given matching is maximum?

First, note that a maximal matching need not be maximum. Take for instance a path withthree edges, and the matching consisting of the middle edge. Similarly, a greedy approach thatkeeps adding edges without removing any, like we used for spanning trees, would probably notlead to a maximum matching. Instead, an algorithm to find maximum matchings will needsome kind of backtracking, where we throw away some edges that we previously selected.The following notion lets us do that in a smart way.

Definition. Given a matching M in a bipartite graph G, a path is alternating if among anytwo consecutive edges on the path, exactly one is in M . An alternating path with at least oneedge is augmenting if its first and last vertices are not covered by M .

Note that an augmenting path always has odd length.

Lemma 7.46. A matching M is maximum if and only if there is no augmenting path for M .

Proof. We prove that M is not maximum if and only if there is an augmenting path forM . First suppose that there is an augmenting path P = v1v2 . . . v2k for the matching M .So v2v3, . . . , v2iv2i+1, . . . , v2k−2v2k−1 ∈ M . Then we can get a larger matching by removingthese edges from M and replacing them by v1v2, . . . , v2i−1v2i, . . . , v2k−1v2k. In other words,we replace M by M ′ = M4E(P ).1 Then M ′ is a matching since v1 and vk were unmatchedby M , and we have |M ′| = |M |+ 1, so M is not maximum.

Now suppose M is not maximum, i.e., there is a matching M ′ with |M ′| > |M |. Let Hbe the graph with V (H) = V (G) and E(H) = M4M ′. Every vertex of H has degree 0, 1 or2, so each component of H is either a cycle, a path, or an isolated vertices. A cycle in H hasthe same number of edges from M and M ′, so |M ′| > |M | implies that there is a path P inD with more edges from M ′ than from M . Then P must be an augmenting path for M .

This result shows that to improve our matching, we just need to find an augmenting path.If no such path exists, then the matching is maximum. But it is not so easy to check if anaugmenting path exists; a naive algorithm would take exponentially many steps. An efficientalgorithm for a maximum matching was found by Edmonds in 1965, but it is beyond thescope of this course. However, the problem becomes much simpler in bipartite graphs.

3 Matchings in bipartite graphs

Let G = (A ∪B,E) be a bipartite graph, and M be a matching in it. Note that the endvertices of every augmenting path P are in different parts (because P has odd length). So ifthere is an augmenting path in G, then it starts in S = A−V (M) and ends in T = B−V (M).Crucially, such a path starting in S will always use an edge not in M to jump to B, and anedge in M to jump back to A.

So let us define DM to be the digraph obtained from G by orienting edges not in Mfrom A to B, and orienting edges in M from B to A. The observations above show that

1We write S4T for the symmetric difference of two sets, i.e., S4T = (S\T ) ∪ (T\S).

25

Page 26: Graph Theory 2018 { EPFL { Lecture Notes. · Graph Theory 2018 { EPFL { Lecture Notes. Lecturer: Daniel Kor andi May 31, 2018 Acknowledgements: These notes are partially based on

augmenting paths in G correspond to directed S-T paths in DM . (An S-T path is a paththat starts in S and ends in T .)

The point is, finding S-T paths in a directed graph is easy (e.g., using breadth-firstsearch). So together with Lemma 7.46, we arrive at the following algorithm for finding amaximum matching in a bipartite graph.

Augmenting Path Algorithmto find a maximum matching in a bipartite G = (A ∪B,E)

(1) Set M = ∅;

(2) Iterate :

(a) Set S = A− V (M), T = B − V (M);

(b) Find any directed S-T path P in DM using BFS; if none exist, go to (3);

(c) Replace M with M := M4P ;

(3) Return M .

4 Perfect matchings

The next question we study is: when does a bipartite graph have a perfect matching?Apart from the trivial condition |A| = |B|, it is easy to see that we need every set X ⊆ Ato have at least |X| neighbors. This condition turns out to be enough, as shown by the nexttheorem. We state it slightly more generally, using the following definitions.

A matching M matches or covers a vertex set X if every vertex of X is contained in anedge of M . For a set X ⊂ V (G), we define the neighborhood of X in G as N(X) = v ∈V (G) \X such that uv ∈ E(G) for some u ∈ X.

Theorem 7.47 (Hall, 1935). Let G = (A∪B,E) be a bipartite graph. Then G has a matchingcovering A if and only if for all X ⊆ A we have |N(X)| ≥ |X|.

Proof. For one direction, note that if G has a matching M that matches A, then the verticesof any X ⊂ A are matched by M to |X| distinct neighbors in B, which implies |N(X)| ≥ |X|.

For the other direction, suppose |N(X)| ≥ |X| for every X ⊆ A. Let M be a maximummatching, and let S = A − V (M) and T = B − V (M) be the unmatched vertices in A andB. By Lemma 7.46 and the discussion above, there is no S-T path in DM . So if XB denotesthe set of vertices in B that can be reached from S via a directed path in DM , then XB isdisjoint from T . In other words, all vertices in XB are matched by M .

Let XA ⊆ A be the set of vertices matched to XB by M (here XA is clearly disjoint fromS). As the matching edges are directed from B to A, the vertices in XA are also reachablefrom S in DM . To finish the proof, we just need to check that N(XA ∪ S) ⊆ XB, becausethis and our assumption with X = XA ∪ S would imply

|XB| ≥ |N(XA ∪ S)| ≥ |XA ∪ S| = |XA|+ |S| = |XB|+ |S|,

and hence S = ∅, which is what we want to prove.To see N(XA ∪ S) ⊆ XB, note that all vertices in XA ∪ S are reachable from S in DM .

But then if there was a vertex b ∈ B − XB adjacent to some a ∈ XA ∪ S, then ab is not amatching edge, so it is directed from a to b in DM . Consequently, b /∈ XB is reachable fromS, which is a contradiction.

26

Page 27: Graph Theory 2018 { EPFL { Lecture Notes. · Graph Theory 2018 { EPFL { Lecture Notes. Lecturer: Daniel Kor andi May 31, 2018 Acknowledgements: These notes are partially based on

If |A| = |B|, then of course every matching covering A covers B, as well. So Hall’s theoremimplies that a bipartite graph G = (A∪B,E) has a perfect matching if and only if |A| = |B|and |N(X)| ≥ |X| for every X ⊆ A.

The property “|N(X)| ≥ |X| for every X ⊆ A” is often referred to as Hall’s condition.Testing this property algorithmically is slow, but it turns out to be a convenient thing tocheck in many theoretical applications.

Corollary 7.48. Let k ≥ 1 be a integer. Every k-regular bipartite graph has a perfectmatching.

Proof. Let G = (A ∪ B,E) be a k-regular bipartite graph. Since every edge touches exactlyone vertex of A, and every vertex of A touches exactly k edges, the number of edges in G isexactly k|A|. By a similar argument, the number of edges is exactly k|B|, so k ≥ 1 implies|A| = |B|.

As discussed above, Hall’s condition would now guarantee a perfect matching. To checkit, let X ⊆ A be a vertex set. We will double-count the edges touching X. On the one hand,there are exactly k|X| such edges. On the other hand, every such edge has its other endpointin N(X), so the number of such edges is at most k|N(X)|. Hence k|X| ≤ k|N(X)|, whichagain implies |X| ≤ |N(X)|.

Finding perfect matchings in regular bipartite graphs can be iterated to get a proper edgecoloring.

Corollary 7.49. Let G be a k-regular bipartite graph. Then χ′(G) = ∆(G).

Proof. χ′(G) ≥ ∆(G) is clear. To show χ′(G) ≤ ∆(G), we apply induction on k.For k = 0, it is clear. For k ≥ 1, apply Corollary 7.48 to find a perfect matching M in G.

Color this matching with some color, and apply induction on the (k − 1)-regular G −M tofind a (k − 1)-edge-coloring of the remaining edges.

Note that this improves Vizing’s theorem for regular bipartite graphs. Actually, we candrop the regularity condition here:

Theorem 7.50 (Konig, 1916). For every bipartite graph G, we have χ′(G) = ∆(G).

The proof is left as a homework problem.

27

Page 28: Graph Theory 2018 { EPFL { Lecture Notes. · Graph Theory 2018 { EPFL { Lecture Notes. Lecturer: Daniel Kor andi May 31, 2018 Acknowledgements: These notes are partially based on

Lecture 8

Konig’s theorem. Flows.

1 Konig’s Theorem

Definition. Given a graph G, a vertex cover for G is a set C ⊂ V (G) such that every edgeof G is incident with a vertex in C.

The maximum size of a matching in G is denoted by ν(G), and the minimum size of avertex cover in G is denoted by τ(G). (Note that the “size” of a matching is the number ofedges in it, while the “size” of a vertex cover is the number of vertices in it.)

Theorem 8.51 (Konig, 1931). Let G = (A∪B,E) be a bipartite graph. Then ν(G) = τ(G).

Proof. It is clear that ν(G) ≤ τ(G), because a vertex cover has to cover every edge of thematching with one of the endpoints of the edge. So to cover a matching of size ν(G), we needat least this many vertices.

Now we show ν(G) ≥ τ(G). Let M be a maximum matching of G, and as before, letS = A−V (M) and T = B−V (M) be the set of unmatched vertices. As observed last time,if M is maximum, there is no S-T path in DM .

Let XB be the set of vertices in B that can be reached from S via a (directed) path inDM , and let YA be the set of vertices in A that cannot be reached from S in DM . Clearly,XB is disjoint from T and YA is disjoint from A. Note also, that either both ends of an edgein M can be reached from S, or neither of them can be. In the former case, the edge has anend vertex in XB, in the latter case it has an endpoint in YA. Consequently, |XB ∪YA| = |M |

We will now show that XB ∪ YA is a vertex cover. Suppose not, then there is an edge uvwith u ∈ A and v ∈ B not covered by this set (i.e., u /∈ YA and v /∈ XB). But uv is not amatching edge, so in DM , it is directed from u to v. But then u ∈ A − YA can be reachedfrom S in DM (by definition), so v should also be reachable via the edge uv. This contradictsv /∈ XB.

So XB ∪ YA is a vertex cover of size ν(G), implying ν(G) ≥ τ(G).

2 Flows

Definition. A network is a graph G = (V,E) with two special vertices, the source s ∈ Vand the sink t ∈ V , together with a non-negative capacity function c : E → Z+.

Definition. A flow in a network G = (V,E) is a function f : V 2 → R such that

1. f(u, v) = −f(v, u) for any u, v ∈ V (skew symmetry)

2.∑

w∈N(v) f(v, w) = 0 for any v ∈ V − s, t (flow conservation)

3. |f(u, v)| ≤ c(u, v) for any uv ∈ E (capacity constraints)

(and f(u, v) = 0 for every non-edge vertex pair).

28

Page 29: Graph Theory 2018 { EPFL { Lecture Notes. · Graph Theory 2018 { EPFL { Lecture Notes. Lecturer: Daniel Kor andi May 31, 2018 Acknowledgements: These notes are partially based on

The value |f | of a flow is defined as∑

w∈N(s) f(s, w). Our main question of study is: whatis the maximum value of a flow in a network G?

A cut in a network G is a partition (S, T ) of the vertices (so S ∩ T = ∅, S ∪ T = V ) suchthat s ∈ S and t ∈ T . For two vertex sets X, Y ⊆ V we define

f(X, Y ) :=∑

x∈X,y∈Y

f(x, y), c(X, Y ) :=∑

x∈X,y∈Y

c(x, y).

We call c(S, T ) the capacity of the cut (S, T ). The following proposition is intuitively clear.

Proposition 8.52. For every cut (S, T ) we have f(S, T ) = |f |.

Proof. By definition, |f | =∑

w∈N(s) f(s, w). Also,∑

w∈N(v) f(v, w) = 0 for all v ∈ S − s, so

|f | =∑v∈S

∑w∈N(v)

f(v, w) =∑u,v∈S

(f(u, v) + f(v, u)

)+

∑u∈S,v∈T

f(u, v)

But here f(u, v) + f(v, u) = 0 by the definition of a flow, so the first term cancels. Theremaining term is

∑u∈S,v∈T f(u, v) = f(S, T ), and the statement follows.

3 Ford-Fulkerson algorithm

So how large can a flow be in a network? Proposition 8.52 implies that for any cut (S, T ),

|f | = f(S, T ) =∑

u∈S,v∈T

f(u, v) ≤∑

u∈S,v∈T

|f(u, v)| ≤∑

u∈S,v∈T

c(u, v) = c(S, T ).

In particular, the maximum value of a flow is bounded by the minimum capacity of a cut.

Theorem 8.53 (Ford–Fulkerson, 1956). In every network, the maximum value of a flowequals the minimum capacity of a cut.

This theorem is also called the max-flow min-cut theorem. The proof of the lower boundis algorithmic, and uses the following definition.

Given a flow f , let Df be the directed graph of edges (u, v) (i.e, u → v) such thatf(u, v) < c(u, v). So (u, v) ∈ E(Df ) means that the edge uv has unused capacity in thenetwork from u to v. We can call these “non-full” edges. The algorithm repeatedly finds ans-t path of non-full edges, and pushes some extra flow through it to increase the value of f .

Ford-Fulkerson Algorithm to find a flow f and a cut (S, T ) such that |f | = c(S, T ).

(1) Set f = 0 for all edges;

(2) While there is an s-t path v0v1 . . . vl in Df (so v0 = s, vl = t):

(a) Let ε := mini=1,...,l

c(vi−1, vi)− f(vi−1, vi).

(b) For i = 1, . . . , l put f(vi−1, vi) := f(vi−1, vi) + ε andf(vi, vi−1) := f(vi, vi−1)− ε.

(3) Define S as the set of all vertices that are reachable by paths from s in Df .

(4) Return f and (S, V − S).

29

Page 30: Graph Theory 2018 { EPFL { Lecture Notes. · Graph Theory 2018 { EPFL { Lecture Notes. Lecturer: Daniel Kor andi May 31, 2018 Acknowledgements: These notes are partially based on

Let us verify that the algorithm works correctly. First, note that f satisfies the threeconditions in the definition of a flow at each step. Second, since in the network all capacitiesare integral, we have that ε > 0 is an integer at each step, and so ε ≥ 1. Therefore, since theflow must be finite (bounded by the capacity of any cut), the algorithm terminates in a finitenumber of steps. Third, (S, V −S) is a cut because s ∈ S and t /∈ S. Finally, by the definitionof Df and the set S, we have f(u, v) = c(u, v) for every edge uv with u ∈ S, v ∈ V − S.Hence f(S, V − S) = c(S, V − S). Since ε is always an integer, we even get the following.

Fact 8.54. If c is integral, then there is an integer maximum flow.

Note that for the algorithm to stop, it was important that c takes integer values. Thesame argument works for rational c, as well (e.g., by multiplying all values with a number tomake c integral), but the algorithm might not stop if c has non-rational values (see problemset). However, Theorem 8.53 holds for any non-negative real capacity function. This canbe proved by approximating it with a rational function and taking the limit. Alternatively,Edmonds and Karp showed that the algorithm stops in a bounded number of steps no matterwhat the capacity function is, provided that it chooses the shortest s-t path of Df in step 2.

4 Directed networks

Flows turn out to be more applicable in directed networks. Everything above works thesame with some slight differences. Note that c is now defined on a digraph, so c(u, v) andc(v, u) are not related. Also, the capacity of a cut c(S, T ) =

∑u∈S,v∈T c(u, v) now only

counts edges directed from S to T . We need to change two things in the definitions:

- Definition of flows: 1. is dropped; 2. is changed to∑

w f(v, w) =∑

w f(w, v)for every v ∈ V − s, t; 3. is changed to 0 ≤ f(u, v) ≤ c(u, v) for directed edges (u, v).

- In Df : edge (u, v) is now added if f(u, v) < c(u, v) or f(v, u) > 0, and the correspondingterm in the definition of ε (free capacity from u to v) is c(u, v)− f(u, v) or f(v, u)

Application: Proof of Theorem 8.51 via Ford-Fulkerson.Given G = (A ∪ B,E), let us create a network by adding a source s that sends an edge ofcapacity 1 to all vertices of A, and adding a sink t that receives an edge of capacity 1 fromall vertices of B. We also orient the edges of G from A to B give them infinite capacities.(Think of ∞ as some large number bigger than |A|.)

Let f be an integer maximum flow. We claim that the G-edges with positive flow form amatching. Indeed, each such edge has f(u, v) ≥ 1. If two such edges shared a vertex u ∈ A,then the inflow at u is at most 1 and the outflow is at least 2, which is not possible. Similarly,two such edges cannot meet in B, either. Hence ν(G) ≤ |f |.

Now let (S, T ) be a minimum cut. Then (S ∩B)∪ (T ∩A) is a vertex cover, because anyuncovered edge (u, v) with u ∈ S ∩A and v ∈ T ∩B would contribute ∞ capacity to c(S, T )(but c(S, T ) ≤ C(s, V − s) ≤ |A| <∞). Here every s-(T ∩A) edge and every (S ∩B)-t edgecontributes 1 to c(S, T ), so we get τ(G) ≤ |S ∩B|+ |T ∩ A| ≤ c(S, T ). Hence

τ(G) ≤ c(S, T ) = |f | ≤ ν(G),

which, together with the trivial ν(G) ≤ τ(G) finishes the proof.

s t

1

1 ∞

∞1

1

30

Page 31: Graph Theory 2018 { EPFL { Lecture Notes. · Graph Theory 2018 { EPFL { Lecture Notes. Lecturer: Daniel Kor andi May 31, 2018 Acknowledgements: These notes are partially based on

Lecture 9

Connectivity.

1 Menger’s theorem

Next we will look at what the Ford-Fulkerson theorem says about networks where everyedge has capacity 1. The results in this section hold for directed and undirected graphs, aswell. We use the following notation: if G = (V,E) is a graph and W ⊆ V, F ⊆ E, thenG −W is the graph with vertex set V \W and edge set E \ e ∈ E : e ∩W 6= ∅, and thegraph G \ F is the graph with vertex set V and edge set E \ F .

Definition. Let G = (V,E) be a (directed) graph, and s, t ∈ V .We say that two paths from s to t (s-t paths) in G are edge-disjoint, if they don’t share

any edges. We say that they are internally vertex-disjoint, if they don’t share any verticesother than s and t.

A subset F ⊆ E is an s-t edge separator, if G−F contains no s-t path. A subset W ⊆ Vis an s-t vertex separator, if G−W contains no s-t path.

The following theorem is one of the cornerstones of graph theory.

Theorem 9.55 (Menger). In a (directed) graph G = (V,E) with s, t ∈ V :

1. Maximum number of edge-disjoint s-t paths = minimum size of an s− t edge separator.

2. If (s, t) /∈ E, then:Max number of internally vertex-disjoint s-t paths = min size of an s−t vertex separator.

Proof. “≤” is clear in both statements: To “destroy” all the s-t paths, we need to delete adistinct edge/vertex from each of them. So any separator has size at least the number ofpaths.

Now we show “≥” for directed G.

1. Take the network on G where all edges have capacity 1. We will prove

max # s-t edge-disjoint paths ≥ max flow = min cut ≥ min s-t edge separator

For the first inequality, take a maximum integer flow f . If |f | > 0, then there is ans-t path P using flow edges. Removing P from f decreases the value of f by 1. Moreprecisely, we “push back” a capacity-1 flow on P to decrease |f | by 1. Crucially, as allcapacities are 1, the new flow does not use any edge of P . So if we repeat this step |f |times, we get |f | edge-disjoint s-t paths, just what we wanted.

The equality in the middle is just the max-flow min-cut theorem (Theorem 8.53). Forthe last inequality, note that the edges appearing in a min cut form an s-t edge sepa-rator. As the edge capacities are all 1, the capacity of this cut is exactly the numberof edges in the edge separator.

2. The key to ensure edge-disjointness in the first statement was to limit the edge capacitiesto 1. To limit the capacities of vertices, we need a trick. Let us define the network Gbased on G as follows:

31

Page 32: Graph Theory 2018 { EPFL { Lecture Notes. · Graph Theory 2018 { EPFL { Lecture Notes. Lecturer: Daniel Kor andi May 31, 2018 Acknowledgements: These notes are partially based on

• for every vertex v ∈ V , we add two vertices vin and vout to G, connected by adirected edge (vin, vout) of capacity 1,

• for every directed edge (u, v) ∈ E, we add (uout, vin) of capacity ∞ to G.

Again, we prove

max # disjoint s-t paths ≥ max sout-tin flow in G = min cut ≥ min s-t separator.

For the first inequality, take a maximum integer sout-tin flow f in G. If |f | > 0, thenthere is an s-t path P using flow edges. As (s, t) /∈ E, P must use a “vertex edge”(vin, vout), and so the capacity of the path P is 1. This means that pushing backcapacity 1 on P decreases |f | by one, and ensures that the “vertex edges” appearing inP are not used by the remaining flow. So repeating this we get |f | paths in G, and thecorresponding paths in G are internally vertex disjoint.

The equality in the middle is again the max-flow min-cut theorem. For the last in-equality, note that the min cut has finite capacity (because (s, t) /∈ E), so all edges inthe cut are “vertex edges” corresponding to a vertex separator. They all have capacity1, so the capacity of this cut is exactly the number of vertices in the separator.

×

×s

tx

y s

x

y

t

in out

source

sink

To prove the undirected variants of Menger’s theorem, one can just replace every undirectededge with two directed edges (one in each direction), and apply directed Menger to it.

2 Connectivity

From now on, we again talk about undirected graphs.

Definition. G = (V,E) is k-connected if |V | > k and G−X is connected for any set X ofat most k − 1 vertices. The greatest k such that G is k-connected is the connectivity κ(G).G is k-edge-connected if G \ F is connected for every set F of at most k − 1 edges. Thegreatest k such that G is k-edge-connected is the edge-connectivity κ′(G) of G.

Let us make some observations.

• G connected ⇐⇒ G is 1-connected ⇐⇒ G is 1-edge-connected.

• If G is k-(edge-)connected, then it is (k − 1)-(edge-)connected.

• κ(Ks) = s− 1, κ(Ck) = κ′(Ck) = 2

Let G be a connected graph. A bridge is an edge e such that G \ e is disconnected. A cutvertex is a vertex v such that G− v is disconnected.

• G is 2-connected ⇐⇒ G has no cut vertex.G is 2-edge-connected ⇐⇒ G has no bridge.

32

Page 33: Graph Theory 2018 { EPFL { Lecture Notes. · Graph Theory 2018 { EPFL { Lecture Notes. Lecturer: Daniel Kor andi May 31, 2018 Acknowledgements: These notes are partially based on

Theorem 9.56 (Global version of Menger’s theorem). Let G = (V,E) be a graph.

1. G is k-edge-connected ⇐⇒ G contains k edge-disjoint paths between any two vertices

2. G is k-connected ⇐⇒ G contains k internally vertex-disjoint paths between any twovertices

This is a strong characterization of k-connected graphs that easily implies the followingnon-trivial facts.

Proposition 9.57. κ(G) ≤ κ′(G) ≤ δ(G).

Proof. κ′(G) ≤ δ(G) is trivial, because deleting all edges touching a vertex disconnects G.To show κ(G) ≤ κ′(G), note that by Theorem 9.56, any two vertices of G are connected

by κ(G) internally vertex-disjoint paths. But then these paths are edge-disjoint, so any twovertices are connected by κ(G) edge-disjoint paths, hence G is κ(G)-edge-connected by theother direction of Theorem 9.56.

Proposition 9.58. G is 2-connected ⇐⇒ any 2 vertices of G are on a cycle.

Proof. By Theorem 9.56, G is 2-connected if and only if any two vertices are connected by2 internally vertex-disjoint paths. But this happens if and only if the two vertices are on acycle (the union of the two paths).

Proof of Theorem 9.56. After the local version, this is not hard to prove.

1. ⇐: If s and t are connected by k edge-disjoint paths, any s-t edge-separator needs tocontain at least one edge from each path. As this is true for any pair of vertices, there isno set F of at most k− 1 edges such that deleting F disconnects G, thereby separatingsome two vertices.

⇒: If G is k-edge-connected, then there is smallest s-t edge separator has size at leastk for every s, t ∈ V . Then by Theorem 9.55, s and t are connected by k edge-disjointpaths for any s, t ∈ V .

2. ⇐: The above argument works the same with vertices instead of edges.

⇒: Again the same argument works, except for adjacent pairs s, t ∈ V . The problemis that we cannot apply Menger’s theorem if st ∈ E. We fix this issue by deleting it,so let G′ = G \ st.

Claim. G′ is (k − 1)-connected.

Using this claim, we can apply Theorem 9.55 to G′ and get k − 1 internally vertex-disjoint s-t paths in G′. Together with the edge st, we get k such paths in G, as needed.All we have left is to prove this claim.

Proof of Claim. Suppose not, i.e., there is a set X of at most k − 2 vertices such thatG′ −X is disconnected. Note that G−X is not disconnected (G is k-connected), andG′ − X = (G − X) \ st, so s and t must be in different components of G′ − X. Nowas G is k-connected, it has at least k + 1 vertices, so there is a vertex w not in X anddifferent from s, t. We may assume that w and t are in different components of G′−X(if not, then w and s are). But then X ′ = X ∪ s is a set of k − 1 vertices such thatG−X = G′−X (because deleting s deletes the edge st), and so G−X is disconnected.This contradicts G being k-connected.

33

Page 34: Graph Theory 2018 { EPFL { Lecture Notes. · Graph Theory 2018 { EPFL { Lecture Notes. Lecturer: Daniel Kor andi May 31, 2018 Acknowledgements: These notes are partially based on

Lecture 10

Extremal graph theory.

1 Triangle-free graphs

Let G be a graph on n vertices that does not contain any triangle as a subgraph (in otherwords, G is K3-free). What is the maximum number of edges that G can have?

With a bit of thinking one can arrive at the conjecture that Kbn2c,dn

2e is optimal, i.e., the

answer is bn2c · dn

2e = bn2

4c. This is indeed the case, although the proof below looks simpler

than it actually is.

Theorem 10.59 (Mantel, 1907). A K3-free graph on n vertices contains at most bn2

4c edges.

Proof. Let v be a vertex in G of maximum degree ∆, and let S = N(v) be its neighborhood(so |S| = ∆). Note that there is no edge with both endpoints in S, otherwise we would get atriangle with v. So every edge of G touches a vertex in V (G) \ S. Also, every vertex touchesat most ∆ edges, so the total number of edges is at most

∆|V (G) \ S| = ∆(n−∆) ≤ bn2/4c.

(At the inequality in the middle, we used the easy fact that ab ≤ (a+b2

)2.)

As an application, we answer the following question.Let a1, . . . , an ∈ Rd be vectors such that |ai| ≥ 1 for each i ∈ 1, . . . , n. What is the

maximum number of pairs satisfying |ai + aj| < 1?

Proposition 10.60. There are at most bn2

4c such pairs.

Proof. Define the graph G on 1, . . . , n where ij is an edge iff |ai + aj| < 1. It is enough toshow that G is triangle-free. But this is indeed the case, since for any i, j, k ∈ [n],

|ai + aj|2 + |aj + ak|2 + |ak + ai|2 = |ai + aj + ak|2 + |ai|2 + |aj|2 + |ak|2 ≥ 3,

so at least one of |ai + aj|2, |aj + ak|2, |ak + ai|2 is at least 1.

2 Cliques

Instead of triangles, we can ask the same question for arbitrary graphs: For a given graphH, what is the maximum number of edges that an H-free graph on n vertices can have?

Definition. The extremal number or Turan number of H, ex(n,H), is the maximum valueof |E(G)| among graphs G on n vertices containing no H as a subgraph.

As a generalization of the triangle-free case, notice that dense graphs not having Kr+1

as a subgraph can be obtained by dividing the vertex set V into r pairwise disjoint subsetsV = V1 ∪ · · · ∪ Vr, |Vi| = ni, n = n1 + · · · + nr, joining two vertices if and only if they liein distinct sets Vi, Vj. We denote the resulting graph by Kn1,...,nr (this is called a completer-partite graph). It has

∑i<j ninj edges. Assuming n is fixed, we get the maximum number

of edges among such graphs when we divide the numbers ni as evenly as possible, that is

34

Page 35: Graph Theory 2018 { EPFL { Lecture Notes. · Graph Theory 2018 { EPFL { Lecture Notes. Lecturer: Daniel Kor andi May 31, 2018 Acknowledgements: These notes are partially based on

|ni − nj| ≤ 1 for all i, j. Indeed, suppose n1 ≥ n2 + 2. By shifting one vertex from V1 toV2, we obtain Kn1−1,n2+1,...,nr , and that contains (n1 − 1)(n2 + 1) − n1n2 = n1 − n2 − 1 ≥ 1more edges than Kn1,...,nr . In particular, if r divides n, then we may choose ni = n

rfor all i,

obtaining (r

2

)(nr

)2

=

(1− 1

r

)n2

2

edges. Turan’s theorem states that this is an upper bound for the number of edges in anygraph on n vertices without an (r + 1)-clique. This result is considered by many to be thestarting point of extremal graph theory. There are many different proofs known; the one wegive here is a generalization of our proof for Theorem 10.59.

Definition. We call the graph Kn1,...,nr with |ni − nj| ≤ 1 the Turan graph, denoted byT (n, r).

Theorem 10.61 (Turan, 1941). Among all the n-vertex simple graphs with no (r+1)-clique,T (n, r) is the unique graph having the maximum number of edges.

Proof. We apply induction on r. The case r = 1 is trivial (actually, the case r = 2 is Mantel’stheorem). Now assume r ≥ 2 and let G be a Kr+1-free graph on n vertices. Let v be a vertexof maximum degree ∆ = ∆(G) and let S = N(v) be the neighborhood of v and T = V (G)\Sbe its complement. Then |S| = ∆. As G contains no (r + 1)-clique and v is adjacent to allvertices of S, we note that G contains no Kr with all vertices in S.

We now construct another Kr+1-free graph H on V (G) that has at least as many edgesas G. We define T to be an independent set of H, but add all edges between S and T to H.Finally, on S, let H be isomorphic to T (∆, r − 1). Then H is a complete r-partite graph, soit clearly is Kr+1-free. To see that H has no fewer edges than G, let eT denote the numberof edges in G touching T , and let eS denote the number of edges not touching T (i.e., withboth endpoints in S). Then |E(G)| = eT + eS.

On the other hand, we know that eT ≤ ∆|T | because each vertex of T has degree at most∆ in G, and we also know that eS ≤ |E(T (∆, r − 1))| using induction and the fact that Gis Kr-free on S. But H contains exactly ∆|T | edges touching T and |E(T (∆, r − 1))| edgesnot touching T , so indeed |E(G)| = eT + eS ≤ |E(H)|.

This argument shows that |E(G)| ≤ |E(H)| for a complete r-partite H. But we have seenthat T (n, r) maximizes the number of edges among complete r-partite graphs, so in fact wehave |E(G)| ≤ |E(H)| ≤ |E(T (n, r))|, as needed.

To prove uniqueness, note that equality can only hold in our previous bound if S inducesthe complete r−1-partite graph T (∆, r−1) (using the induction hypothesis), and T touchesexactly ∆nr edges in G. But the latter can only happen if T is an independent set in G.Indeed, the sum of the degrees of the vertices in T counts each edge spanned by T twice, andeach edge connecting T and S once. As ∆ is the maximum degree in G, the sum of degreesis at most ∆nr, so T can only touch this many edges if it spans none of them. But then Gis r-partite and since it has the maximum number of edges, G = T (n, r).

Turan’s theorem shows that ex(n,Kr+1) is essentially equal to(1− 1

r

)n2

2(they are equal

when n is divisible by r and they differ by a constant when n is not divisible by r). Butwhat happens for other graphs? What is ex(n,H)? Surprisingly, the answer pretty muchonly depends on the chromatic number of H (at least when χ(H) ≥ 3):

35

Page 36: Graph Theory 2018 { EPFL { Lecture Notes. · Graph Theory 2018 { EPFL { Lecture Notes. Lecturer: Daniel Kor andi May 31, 2018 Acknowledgements: These notes are partially based on

Theorem 10.62 (Erdos-Stone-Simonovits). Let H be a graph of chromatic number χ(H) =r + 1. Then for every ε > 0 and large enough n,(

1− 1

r

)·(n

2

)≤ ex(n,H) ≤

(1− 1

r

)·(n

2

)+ εn2.

3 Bipartite graphs

For bipartite H, the Erdos-Stone-Simonovits theorem only says that ex(n,H) = o(n2).It is one of the biggest questions in graph theory to determine the order of magnitude ofthe extremal number of bipartite graphs. There are very few graphs for which we know theanswer. One such example is H = C4 = K2,2.

Theorem 10.63. If a graph G on n vertices contains no K2,2, then

|E(G)| ≤⌊n

4(1 +

√4n− 3)

⌋.

Proof. Let G be a graph on n vertices without a 4-cycle. Let S be the set of “cherries”, i.e.,pairs (u, v, w) where u is adjacent to both v and w, with v 6= w:

w.v

u

We will count the elements of S of in two different ways. Summing over u, we find |S| =∑u∈V (G)

(d(u)

2

). On the other hand (and this is the crucial observation): every pair v, w

has at most one common neighbor (because G is K2,2-free), so |S| ≤(n2

).

The rest of the proof is just calculations. So far we have∑u∈V

(d(u)

2

)≤(n

2

)or equivalently, ∑

u∈V

d(u)2 ≤ n(n− 1) +∑u∈V

d(u). (1)

Now applying the Cauchy-Schwarz inequality to the vectors (d(u1), . . . , d(un)) and (1, . . . , 1),

we get(∑

u∈V d(u))2 ≤ n

∑u∈V d(u)2. This, together with (1), implies(∑u∈V

d(u)

)2

≤ n2(n− 1) + n∑u∈V

d(u).

Here the sum of the degrees is 2|E(G)|, so we get 4|E(G)|2 ≤ n2(n− 1) + 2n|E(G)|. Orequivalently,

|E(G)|2 − n

2|E(G)| − n2(n− 1)

4≤ 0.

Solving this quadratic equation yields the theorem.

36

Page 37: Graph Theory 2018 { EPFL { Lecture Notes. · Graph Theory 2018 { EPFL { Lecture Notes. Lecturer: Daniel Kor andi May 31, 2018 Acknowledgements: These notes are partially based on

The last theorem shows that ex(n,K2,2) = O(n3/2). This upper bound is tight in thesense that there are K2,2-free graphs on n vertices with Ω(n3/2) edges, as shown below.

Example. Let p ≥ 3 be a prime, and G0 be the graph on the vertex set Zp × Zp where(x, y) and (x1, y1) are connected by an edge and only if x + x1 = yy1. (Technically this is amultigraph as it has loops).

Note that G0 is p-regular. Indeed, for every x, y, y1 there is a unique choice of x1 such that(x, y) and (x1, y1) are adjacent. Also, loops correspond to solutions of the equation 2x = y2.There is therefore one loop for every choice of y, giving p loops in total. Let G be the graphwe obtain by deleting the loops from G0.

Now, G has n = p2 vertices, and 12(np − p) = (1

2+ o(1))n3/2 edges. It also has no

K2,2s. Indeed, for any (x1, y1) and (x2, y2), a vertex (x, y) adjacent to both of them satisfiesx + x1 = yy1 and x + x2 = yy2, so x1 − x2 = y(y1 − y2). If y1 = y2 then x1 = x2, so ifour chosen vertices (x1, y1) and (x2, y2) were distinct then y1 − y2 6= 0. Then y is uniquelydetermined from the last equation, and this defines x, as well.

It is not too hard to generalize the proof of Theorem 10.63 to arbitrary Ks,t, and get thefollowing theorem:

Theorem 10.64 (Kovari-Sos-Turan, 1954). For any integers 1 ≤ s ≤ t, there is a constant

c such that ex(n,Ks,t) ≤ cn2− 1s .

However, lower bound constructions where the number of edges has the same order ofmagnitude is only known for s = t = 2 (see above) and s = 2, t = 3.

For even cycles, the following result is the best known upper bound. Once again, matchingconstructions are only known for k = 2, 3, 5.

Theorem 10.65 (Bondy-Simonovits, 1974). For any integer 2 ≤ k, there is a constant c

such that ex(n,C2k) ≤ cn1+ 1k .

We do not prove these theorems here.

37

Page 38: Graph Theory 2018 { EPFL { Lecture Notes. · Graph Theory 2018 { EPFL { Lecture Notes. Lecturer: Daniel Kor andi May 31, 2018 Acknowledgements: These notes are partially based on

Lecture 11

The probabilistic method.

Probabilistic tools turn out to be extremely useful for certain combinatorial problems. Atfirst, applications might feel like magic: problems that have nothing to do with probabilityoften have simple solutions if we introduce some randomness. Deeper theoretical results (likethe so-called Szemeredi regularity lemma) show some inherent connection between graphsand random structures.

However, (fortunately or unfortunately) this is not the course to go this deep, so we willhave to stick with the magical results.

1 Review of basic notions

We will use standard notions from probability theory, although in a quite restricted set-ting: we will always work with a probability space that is defined on a finite base set Ω witha probability mass function p : Ω→ [0, 1] satisfying

∑ω∈Ω p(ω) = 1. The events in this prob-

ability space are all subsets E ⊆ Ω, and the probability that E holds is P[E] =∑

ω∈A p(ω).A random variable is just a function X : Ω→ R, and the expected value or expectation of

a random variable X is

E[X] =∑x∈R

x · P[X = x] =∑ω∈Ω

p(ω) ·X(ω).

A very important fact (that can be easily seen from the right-hand side of this equality) isthe linearity of expectation, i.e., that for any two random variables X and Y and any real c,we have E[X + Y ] = E[X] + E[Y ] and E[cX] = cE[X].

Two events E1 and E2 are said to be independent if P[E1 ∩E2] = P[E1] · P[E2]. For morethan two events, E1, . . . , Ek are independent if for any I ⊆ 1, . . . , k, we have

P

[⋂i∈I

Ei

]=∏i∈I

P[Ei].

Similarly, the random variables X1, . . . , Xk are independent if for any x1, . . . , xk and anyI ⊆ 1, . . . , k, we have

P

[⋂i∈I

Xi = xi

]=∏i∈I

P[Xi = xi].

2 Simple applications

As a first example, let us give a new proof of the following fact. In Lecture 2, we gave analgorithmic proof, this time we provide a probabilistic argument.

Proposition 11.66. Any graph G contains a bipartite subgraph H with |E(H)| ≥ |E(G)|/2.

Proof. Let us take a random partition of the vertices into parts A and B, where each vertexis independently assigned to A or B with probability 1/2. So Ω is the set of all partitions. Forevery edge e ∈ E(G), let Xe be the indicator random variable for the event that e “crosses”

38

Page 39: Graph Theory 2018 { EPFL { Lecture Notes. · Graph Theory 2018 { EPFL { Lecture Notes. Lecturer: Daniel Kor andi May 31, 2018 Acknowledgements: These notes are partially based on

between A and B. Then X =∑

e∈E(G) Xe is a random variable that counts the number ofedges crossing between A and B. Thus the expected number of edges crossing is

E[X] = E

[∑e∈E

Xe

]=∑e∈E

E[Xe].

Here for an edge e = uv, we have

E[Xe] = P[e crossing] = P[u ∈ A, v ∈ B] + P[u ∈ B, v ∈ A] =1

2· 1

2+

1

2· 1

2=

1

2,

so E[X] =∑

e∈E 1/2 = |E(G)|/2. But then there must be a partition ω ∈ Ω such thatX(ω) ≥ |E(G)|/2 (otherwise the expectation would be strictly smaller).

Note that this is only an existence proof. We do not get any information on how to findsuch a subgraph.

For our next application, let us introduce the notion of hypergraphs, a generalization ofgraphs. A hypergraph H is a pair (V,E), where V is a finite vertex set, and E is a collectionof subsets of V , called hyperedges. An r-uniform hypergraph is one where all hyperedgescontain exactly r vertices. (So graphs are 2-uniform hypergraphs.) We can generalize graphcolorings to hypergraph coloring in a straightforward manner: we say that a hypergraph His k-colorable if its vertices can be colored with k colors so that there is no monochromaticedge, i.e., every edge gets at least 2 different colors.

Proposition 11.67. Every r-uniform hypergraph H with fewer than 2r−1 edges is 2-colorable.

Proof. Consider a random coloring where every vertex of H is colored red or blue withprobability 1/2, independently of the other vertices. Then Ω is the set of all vertex colorings.Let e1, . . . , em be the edges of H, where m < 2r, and let Ei be the event that all vertices ofei get the same color. What is the probability that Ei holds?

P[all vertices of ei are red] = (1/2)r

P[all vertices of ei are blue] = (1/2)r

⇒ P[Ei] = 1/2r−1.

But then P[⋃mi=1Ei] ≤

m2r−1 < 1, so with positive probability none of the Ei holds, i.e., all

edges get 2 colors. In particular, there is some red-blue coloring ω ∈ Ω where no edge ismonochromatic.

Alternatively, we could have defined the indicator variables Xi of ei being monochromatic.Then X =

∑mi=1Xi counts the number of monochromatic edges, and

E[X] = E

[m∑i=1

Xi

]=

m∑i=1

E[Xi] =m∑i=1

P[Ei] =m

2r−1< 1.

Hence there is a coloring where X < 1, and since X is an integer, this must mean X = 0.

For our third example, suppose we have sets A1, . . . , Am and B1, . . . , Bm such that |Ai| = aand |Bi| = b for every i, and they also satisfy Ai ∩ Bi = ∅ and Ai ∩ Bj 6= ∅ for every i 6= j.(So we have disjoint pairs of sets (Ai, Bi), that pairwise intersect each other in some sense.)We call this an intersecting family of set pairs. The question we are interested in is how largem can be in terms of a and b.

For example, we can take a base set X of size a+ b, and take all(a+ba

)partitions of it into

some Ai of size a and Bi of size b. This gives a good construction for m =(a+ba

). As it turns

out, it is impossible to give a construction for larger m, even if the base set is allowed to bearbitrarily large. This is called the Bollobas set pairs inequality.

39

Page 40: Graph Theory 2018 { EPFL { Lecture Notes. · Graph Theory 2018 { EPFL { Lecture Notes. Lecturer: Daniel Kor andi May 31, 2018 Acknowledgements: These notes are partially based on

Lemma 11.68 (Bollobas, 1965). m ≤(a+ba

).

Proof. Let X =⋃mi=1Ai ∪ Bi be the set of all N = |X| elements appearing in the set pairs.

Consider a random permutation (ordering) of the vertices chosen uniformly. So Ω is the setof all permutations of X, and each has probability 1

N !.

Let Ei be the event that the elements of Ai precede the elements of Bi in this randompermutation. Then P[Ei] = 1/

(a+ba

). Indeed, this event only depends on the relative positions

of the elements in Ai ∪ Bi, so we can ignore all other elements in X. Also, out of the(a+ba

)options for picking the places of Ai among these a+ b elements, only the one where we pickthe first a places is in Ei.

Crucially, the event Ei is disjoint from every other event Ej. Indeed, if Ei holds, then Aiprecedes Bi. Also, from the intersection assumption, there must be elements x ∈ Ai∩Bj andy ∈ Bi ∩ Aj. But then x ∈ Bj precedes y ∈ Aj, so Ej cannot hold. Now putting everythingtogether, we get (using the disjointness for the middle equality)

1 ≥ P

[m⋃i=1

Ei

]=

m∑i=1

P[Ei] =m(a+ba

) ,and thus m ≤

(a+ba

).

3 Saturation

We say that a graph G is H-saturated if it is a maximal H-free graph, i.e., if G doesnot contain H as a subgraph, but if we add any missing edge to G, we create a subgraphisomorphic to H. The minimum number of edges in an H-saturated graph on n vertices iscalled the saturation number, and is denoted by sat(n,H). Note that this saturation problemis in some sense the opposite of the Turan problem: ex(n,H) is the maximum number ofedges in an H-saturated graph.

It is easy to check that sat(n,K3) = n− 1, because the star K1,n−1 is K3-saturated, butthere is no disconnected K3-saturated graph. In general, for cliques we have the following.

Theorem 11.69 (Zykov, 1949, Erdos-Hajnal-Moon, 1964).

sat(n,Ks) =

(n

2

)−(n− s+ 2

2

)= (s− 2)n−

(s− 2

2

).

Proof. The upper bound is a construction: Let G be a clique on some s − 2 vertices A,together with all edges connecting A with the n − s + 2 remaining vertices B. This G isKs-saturated, because its missing edges are in B, and adding such an edge uv creates a cliqueon A∪u, v. Also, G has

(n2

)−(n−s+2

2

)edges because there are

(n−s+2

2

)missing edges in B.

For the lower bound, take a Ks-saturated G = (V,E), and let f1, . . . , fm be the missingedges in G. Then the addition of each fi = uivi creates an s-clique on some vertex set Xi.Let us define the sets Ai = ui, vi and Bi = V −Xi. We claim that they form a intersectingfamily of set pairs.

Indeed, |Ai| = 2, Bi = n− 2 and Ai ∩Bi = ∅ are clear from the definition. We just needto check that Ai ∩ Bj 6= ∅ for every i 6= j. But this is clear, because we know that fj isthe only missing edge in Xj. In particular, fi has at least one endpoint outside Xj, i.e., inBj = V −Xj. So Ai ∩Bj is non-empty: it contains this endpoint.

Now Lemma 11.68 gives m ≤(n−s+2

2

). But since m is the number of missing edges, this

implies that G has at least(n2

)−(n−s+2

2

)edges.

40

Page 41: Graph Theory 2018 { EPFL { Lecture Notes. · Graph Theory 2018 { EPFL { Lecture Notes. Lecturer: Daniel Kor andi May 31, 2018 Acknowledgements: These notes are partially based on

Lecture 12

Ramsey’s theorem.

1 Ramsey’s theorem. Upper bounds

Proposition 12.70. If the edges of K6 are colored red and blue, then there is a red K3 or ablue K3.

Proof. Pick a vertex v. It has five incident edges, among which there must be three red edgesor three blue edges. Without loss of generality, assume there are three red edges vx, vy, vz. Ifone of the edges xy, xz, yz is red, then it forms a red K3 together with the two correspondingedges to v. Otherwise, the edges xy, xz, yz are all blue, so they form a blue K3.

We say that a clique in an edge-colored graph is monochromatic if all the edges in theclique have the same color.

Theorem 12.71 (Ramsey, 1930). For every positive integer s, there is an N such that any2-edge-colored KN contains a monochromatic clique of size s.

The smallest such N is called the Ramsey number of s. More generally,

Definition. The Ramsey number R(s, t) is the smallest integer N such that whenever theedges of KN are colored red or blue, this coloring contains a red Ks or a blue Kt.

Proposition 12.70 thus states that R(3, 3) ≤ 6. In fact, we have R(3, 3) = 6, because theedges of K5 can be colored with red and blue without creating a monochromatic K3: We cantake a C5 in K5 and color its edges red; the remaining edges form another C5, which we colorblue.

Ramsey’s theorem, as stated above, says that R(s, s) is always finite. The original state-ment is a lot more general, for example it also implies that R(s, t) is finite. However, theoriginal bounds that Ramsey got were quite weak. The main results of this lecture are thefollowing lower and upper bounds on R(s, s) (of course, the upper bound serves as a prooffor Ramsey’s theorem).

Theorem 12.72 (Erdos-Szekeres, 1935; Erdos, 1947). For every s ≥ 2,

2s/2 ≤ R(s, s) ≤ 22s

Although these bounds seem far apart from each other (and indeed they are), they arebasically the state of the art today, as well: no improvement in the exponent is known foreither bound. Closing the gap is one of the biggest open problems in combinatorics.

Let us start with the proof of the upper bound. It is actually easier to prove a strongerresult:

41

Page 42: Graph Theory 2018 { EPFL { Lecture Notes. · Graph Theory 2018 { EPFL { Lecture Notes. Lecturer: Daniel Kor andi May 31, 2018 Acknowledgements: These notes are partially based on

Theorem 12.73 (Erdos-Szekeres, 1935). For every s, t ≥ 3 we have R(s, t) ≤(s+t−2s−1

).

This readily implies R(s, s) ≤(

2s−2s−1

)≤ 22s−2.

Proof. We apply induction on s+ t.For s = 2 the statement is true, because clearly R(2, t) = t. Similarly, for t = 2, we have

R(s, 2) = s, so the bound in the theorem holds. This will be our base case.For the induction step, it is enough to show the following (as

(s+t−2s−1

)=(s+t−3s−2

)+(s+t−2s−1

)).

R(s, t) ≤ R(s− 1, t) +R(s, t− 1). (2)

Let N = R(s − 1, t) + R(s, t − 1) and consider a coloring of the edges of KN with red andblue. Pick a vertex v. It has either at least R(s − 1, Kt) red edges or at least R(s, t − 1)blue edges. The cases are symmetric, so we can assume without loss of generality that v hasR(s−1, t) red edges. Consider the 2-colored complete graph on the corresponding R(s−1, t)neighbors of v. By the definition of R(s−1, t), this graph has either a red Ks−1 or a blue Kt.In the first case the red Ks−1 together with v will form a red Ks, and in the second case weget a blue Kt, so we get the monochromatic clique we were looking for in both cases. Thisestablishes (2) and finishes the proof.

Before proving the lower bound, let us show an interesting application. We need to definemulticolor Ramsey numbers first.

Definition. The k-color Ramsey number Rk(s1, . . . , sk) is the smallest integer N such thatwhenever the edges of KN are colored with k colors, there is an i such that the coloringcontains a Ksi in color i.

The following simple statement implies (using induction on k) that Rk(s1, . . . , sk) is finitefor any choice of k, s1, . . . , sk. The proof is left as an exercise.

Proposition 12.74. We have Rk(s1, . . . , sk) ≤ R(s1, . . . , sk−2, R(sk−1, sk)).

We finish the section with the following cute corollary.

Corollary 12.75 (Schur, 1916). For every k there exists an N such that whenever thenumbers 1, . . . , N are k-colored, there are x, y, z of the same color that satisfy x+ y = z.

Proof. We will show that N = Rk(3)− 1 = Rk(3, . . . , 3)− 1 works. So let c : 1, . . . , N →1, . . . , k be an arbitrary k-coloring of the integers. We define the k-edge-coloring c′ onKN+1 whose vertex set is 1, . . . , N + 1, as follows:

c′(ij) = c(|i− j|).

As this is a k-edge-colored complete graph on Rk(3) vertices, it must contain a monochromatictriangle hij (with h < i < j, say). But then x = j − i, y = i− h and z = j − h are numbersin 1, . . . , N of color c(x) = c′(ij), c(y) = y′(hi), c(z) = c′(hj), which are all the same, andthey also satisfy x+ y = (j − i) + (i− h) = j − h = z, proving our result.

42

Page 43: Graph Theory 2018 { EPFL { Lecture Notes. · Graph Theory 2018 { EPFL { Lecture Notes. Lecturer: Daniel Kor andi May 31, 2018 Acknowledgements: These notes are partially based on

2 Ramsey numbers. Lower bounds

We proceed to the lower bound. Its proof is one of the first applications of the probabilisticmethod in combinatorics, and was a major breakthrough at the time.

Theorem 12.76 (Erdos, 1947). For every s ≥ 3, 2s/2 ≤ R(s, s).

Proof. We will actually prove the following.

If 21−(s2)(n

s

)< 1, then R(s, s) > n. (3)

To see that this is sufficient, we just need to check that n = 2s/2 satisfies the inequality onthe left. Indeed, it is easy to see that

(ns

)< ns

s!< ns

21+s/2 for s ≥ 3, so we obtain

21−(s2)(n

s

)< 21−s2/2+s/2 · ns

21+s/2= 2−s

2/2ns = (n/2s/2)s = 1

for n = 2s/2.Now let us prove (3). Color the edges of Kn randomly red or blue with probability 1/2,

independently of the other edges. For each set A of s vertices, let XA be the indicator randomvariable that A forms a monochromatic clique. Then X =

∑AXA is the random variable

that counts the number of monochromatic s-cliques in this randomly colored graph. Here

E[X] =∑A

E[XA] =

(n

s

)21−(s

2)

because

E[XA] = P[A is monochromatic] = P[A is blue] + P[A is red] = 2 · (1/2)(s2).

So if we assume 21−(s2)(ns

)< 1, then the expected number of monochromatic s-cliques in

the graph is smaller than 1. In particular, there is a coloring where the number of monochro-matic s-cliques is less than 1, i.e., zero. This is what we wanted to prove.

Note that with an additional trick, we can improve the argument a little bit. Indeed, thefollowing is true.

If 21−(s2)(n

s

)= o(n), then R(s, s) > (1− o(1))n. (4)

To prove this, we can use the same argument to see that the expected number of monochro-matic s-cliques in the random coloring above is o(n). Now this is not a good Ramsey graph,but we can easily turn it into one: delete a vertex from each of these monochromatic s-cliques.This way we only delete o(n) vertices, so (1 − o(1))n vertices remain in the graph. On theother hand, it contains no monochromatic s-cliques, as we have “destroyed” them all.

If one does the calculations carefully (as we did not), (3) implies a lower bound R(s, s) ≥1√2es2s/2(1+o(1)), whereas (4) implies R(s, s) ≥ 1

es2s/2(1+o(1)), an improvement by a factor

of√

2. However, this is still extremely far from the upper bound.

The definition of the Ramsey number R(s, t) is often stated in terms of graphs withoutedge colors: If one deletes all red edges from a 2-edge-colored complete graph, and onlykeeps the blue edges, then a red clique will correspond to an empty set, and a blue clique

43

Page 44: Graph Theory 2018 { EPFL { Lecture Notes. · Graph Theory 2018 { EPFL { Lecture Notes. Lecturer: Daniel Kor andi May 31, 2018 Acknowledgements: These notes are partially based on

corresponds to an actual clique in the graph. With this correspondence in mind, the Ramseynumber R(s, t) can be equivalently defined as the smallest integer N such that every graphon N vertices contains an empty set of size s or a clique of size t. (Or: every N -vertex graphG satisfies α(G) ≥ s or ω(G) ≥ t.)

Our lower bound construction is then the Erdos-Renyi random graph G(n, 1/2), where,more generally, G(n, p) is defined as a random graph, where each pair of vertices is connectedby an edge with probability p, independently of the others.

3 An upper bound on Rk(3)

We finish this lecture by giving an upper bound on the k-color Ramsey number Rk(3),that we used in Schur’s theorem. The proof is quite similar to the Erdos-Szekeres upperbound.

Proposition 12.77. For every k ≥ 2, Rk(3) ≤ be · k!c+ 1.

Proof. We apply induction on k. For k = 2, the right-hand side is 6, and indeed, R2(3) =R(3, 3) ≤ 6.

Now suppose k > 2, and take a k-edge-colored complete graph on be · k!c + 1 vertices.Note that be · k!c =

∑ki=0

k!i!

. Indeed, e · k! =∑∞

i=0k!i!

, and here∑k

i=0k!i!

is an integer, and∑∞i=k+1

k!i!< 1. Using this, we can observe the following:

be · k!c =k∑i=0

k!

i!= 1 +

k−1∑i=0

k!

i!= 1 + k ·

k−1∑i=0

(k − 1)!

i!= 1 + kbe · (k − 1)!c.

Now a vertex v in our graph has be · k!c edges touching it, colored with k colors. Theabove equation then implies that at least be ·(k−1)!c+1 of these edges have the same color i.Let X be the set of neighbors of v in color i. If the graph contains an edge in color i betweentwo vertices of X, then it forms a K3 in color i with v. Otherwise, the edges between X arecolored with k− 1 colors only, and since |X| ≥ be · (k− 1)!c+ 1, we get a monochromatic K3

by induction.

44

Page 45: Graph Theory 2018 { EPFL { Lecture Notes. · Graph Theory 2018 { EPFL { Lecture Notes. Lecturer: Daniel Kor andi May 31, 2018 Acknowledgements: These notes are partially based on

Lecture 13

Graph algorithms.

In this last lecture we will go into some more detail on algorithms for graphs. We willfocus on the minimum spanning tree problem and the shortest path problem. In Lectures 2and 3 we saw that the BFS algorithm solves both problems for unweighted graphs, but nowwe consider weighted graphs (i.e. the graphs come with a weight function w : E(G) → R),which makes the problems and the algorithms more interesting.

For simplicity, in this lecture we assume the graphs to be undirected and connected. Wewill discuss the algorithms in a fairly informal way, without spending too much time onimplementation details.

1 Minimum spanning trees

Minimum Spanning Tree Problem: Given a connected weighted undirected graphG, find a spanning tree of minimum weight.

Greedy Tree-Growing Algorithm. The easiest thing to try is a greedy approach: re-peatedly add the smallest edge that we can add while preserving connectedness and acyclicity(i.e. while maintaining a tree all along).

Tree-Growing Algorithm for connected weighted undirected graphs

1. Start with T being a single vertex;

2. Repeat the following until V (T ) = V (G):

(a) Find e ∈ ∂(T ) with minimum w(e);

(b) Add e to T .

3. Return T .

This algorithm is often called Prim’s algorithm.

Theorem 12.78. The Tree-Growing Algorithm returns a minimum spanning tree.

Proof. Call a tree good if it is contained in a minimum spanning tree. Clearly the emptygraph is good. We will inductively show that all the trees occurring during the algorithmare good, hence so is the final tree T . Since the final tree T has V (T ) = V (G), it is itself aspanning tree, so it follows that it has minimum weight.

Suppose we are in the second step of the algorithm with a good tree T ′, contained in aminimum spanning tree T ∗. Then we want to show that T ′+ e is also good, where e ∈ ∂(T ′)with minimum w(e). If e ∈ T ∗, then this is obvious, so suppose e 6∈ T ∗. Adding e to T ∗

creates a cycle, which must contain another edge f ∈ ∂(T ′). Since the algorithm chose e overf , we have w(f) ≥ w(e). Then T ∗∗ = T ∗ − f + e is a minimum spanning tree containing T ′

and e, which means T ′ + e is good.

45

Page 46: Graph Theory 2018 { EPFL { Lecture Notes. · Graph Theory 2018 { EPFL { Lecture Notes. Lecturer: Daniel Kor andi May 31, 2018 Acknowledgements: These notes are partially based on

Greedy Forest-Growing Algorithm. There are different greedy approaches for finding aminimum spanning tree, where a different property is preserved in the process. For instance,one can just preserve acyclicity (i.e. maintain a forest), and in the end the connectednesswill follow just from the number of edges. This leads to:

Forest-Growing Algorithm for connected weighted undirected graphs

1. Start with the empty graph F on the vertex set V (G), and set S = E(G);

2. Repeat the following until S = ∅:

(a) Find e ∈ S with minimum w(e);

(b) Add e to F , unless that creates a cycle; remove e from S.

3. Return F .

This is usually called Kruskal’s algorithm. The proof that it indeed returns a minimumspanning tree is left to the exercises.

2 Shortest paths

Shortest Path Problem: Given a connected weighted undirected graph G and a, b ∈V (G), find a path from a to b of minimum weight, if one exists.

Unweighted graphs. Note first that the greedy approach does badly for the Shortest PathProblem: building a path by greedily adding shortest the available edge will probably noteven give a path from a to b, let alone a shortest path. Fortunately, in an earlier lecture wesaw that a BFS-tree gives shortest paths from its root. We will start from that idea, butphrase it in terms of distance sets: Dk will be the set of vertices at distance k from a.

BFS for distance sets from a for connected unweighted graphs

1. Set D0 = a and k = 0.

2. Repeat the following until ∪ki=0Dk = V (G):

(a) Set k := k + 1.

(b) Compute Dk = N(Dk−1)\(∪k−1i=0Dk

);

3. Return the sets Di for i = 0, 1, . . . , k.

Distance from a to b: We have dist(a, b) = i iff b ∈ Di. More generally, if we defined : V (G)→ Z≥0 by d(v) = i iff v ∈ Di, then d(v) = dist(a, v) for any v ∈ V (G).

Of course, if you only cared about b, you could let the algorithm stop as soon as b ∈ Dk.Shortest ab-path: We can find the shortest path from a to b by going backwards from b. Ifb ∈ Dm, set vm = b, and repeatedly choose

vi ∈ N in(vi+1) ∩Di,

from i = m− 1 to i = 0. Then v0 = a and P = av1v2 · · · vm−1b is a shortest ab-path.

46

Page 47: Graph Theory 2018 { EPFL { Lecture Notes. · Graph Theory 2018 { EPFL { Lecture Notes. Lecturer: Daniel Kor andi May 31, 2018 Acknowledgements: These notes are partially based on

Dijkstra’s algorithm. Can we do the same with arbitrary weights? Think of an un-weighted graph as having weight 1 at every edge. Then we could handle any graph withnonnegative integral weights by splitting an edge with weight k into k edges of weight 1.That gives an unweighted graph with corresponding shortest paths, so we could use the BFSalgorithm above to find the shortest paths. This will give a shortest path, but it is a badalgorithm, because it works with a graph whose number of vertices depends on the weightsin the original graph. That implies that the running time is not O(f(n)) for any functionf(n) of n = |V (G)|, so it certainly isn’t polynomial.

Nevertheless, this idea does lead to a good algorithm. When we apply BFS to the modifiedgraph with weight 1 edges, we encounter the original vertices in the order of their distancefrom the starting vertex. If we keep track of that order as we go along, we can skip all theintermediate steps. This is what Dijkstra’s algorithm does.

Dijkstra’s Algorithm for shortest paths from a for nonnegative weights

1. Set d(a) = 0 and d(v) =∞ for v 6= a, and S = ∅;

2. Repeat the following until S = V (G):

(a) Take u 6∈ S with minimum d(u);

(b) Recompute d(v) for all v ∈ N(u)\S:if d(v) > d(u) + w(uv), set d(v) := d(u) + w(uv) and p(v) = u;

(c) Add u to S.

3. Return d and p.

Shortest ab-path: The predecessor function p defines a path from a to any vertex b ∈ V (G):Set m = d(b), vm = b, and iteratively set vk = p(vk+1), until v0 = a. Then P = av1v2 · · · vm−1bis a shortest path from a to b.

Theorem 12.79. For a connected weighted graph with nonnegative weights, and a vertex a,Dijkstra’s Algorithm correctly returns the distances from a and the shortest paths from a.

Proof. We claim that for every v ∈ S we have d(v) = dist(a, v). This claim would imply thetheorem. To prove it, consider the moment when the algorithm chooses u 6∈ S with minimumd(u). By the way we have computed d(u) (and by p), there is a path from a to u of weightd(u), so we have dist(a, v) ≤ d(u).

Suppose that dist(a, v) < d(u), so there is a shorter path P ′ from a to u. Let u′ be thefirst vertex on P ′ that is outside S (which could be u itself), and let v′ ∈ S be the vertex onP ′ before u′. Since v′ ∈ S, we have d(v) = dist(a, v′) by induction. Since the weight of P ′ isless than d(u), we have d(v′) +w(v′u′) < d(u) (knowing that there are no negative weights).But then, after the previous step where we updated the neighbors of v′, we must have hadd(u′) ≤ d(v′) + w(v′u′) < d(u). If u = u′, this is a contradiction, while if u 6= u′, then weshould have chosen u′ before u, also a contradiction.

47

Page 48: Graph Theory 2018 { EPFL { Lecture Notes. · Graph Theory 2018 { EPFL { Lecture Notes. Lecturer: Daniel Kor andi May 31, 2018 Acknowledgements: These notes are partially based on

Negative weights. BFS and Dijkstra may not work when the graph has negative weights.For instance, for

a b2

c

3 −2

the algorithm will end with d(b) = 2, when it should be 1. It will choose b before c, setd(b) = 2 and put b into S, after which it no longer updates d(b).

We could try to fix this by setting d(c) = 3 and then updating d(b) = d(c) − 2 = 1, butthen we should also update d(c) = d(b) − 2 = −1, and then we have a problem. This laststep would not correspond to a path but to a walk, which we should not be considering, butthis kind of update cannot make that distinction.

In general, this problem is actually NP-hard, for instance because we could show that analgorithm for shortest paths that allows negative weights could also solve the Hamilton pathproblem, which is NP-hard.

48