In this section we study the problem of deciding whether a graph isconnected, i.e., has only onepiece. As a byproduct, we introduce the concepts that name the section and prove several important results related to them. In particular, we give a necessary and sufficient condition for the existence of an Eulerian walk in a connected graph, and characterize bipartite graphs in terms of cycles.
Definition 5.18 Awalkoflengthk≥1 in a graphGis a sequence
P =(u0, u1, . . . , uk) (5.3) of (not necessarily distinct) vertices ofG, such thatui−1is adjacent toui, for 1≤ i≤k. A walkPas above is said to beclosedifu0=uk.
The graphs we wish to qualify are those for which there is a walk between any two vertices. Since these graphs are quite important for our subsequent discussion, we isolate them in the coming
Definition 5.19 A graph isconnectedif there exists a walk between any two of its vertices. A non connected graph is said to bedisconnected.
The coming proposition furnishes a simple (sufficient, albeit obviously not necessary) criterion for a graph to be connected. For its statement, we need to introduce a concept which will also be useful in other future context: given a graph G=(V;E), itsminimum degreeis the nonnegative integerδ(G)given by
δ(G)=min{dG(u);u∈V (G)}. (5.4) Proposition 5.20 IfGis a graph ofnvertices for whichδ(G) ≥ n2, thenGis connected.
Proof Ifn=1, there is nothing to do. Ifn=2, thenδ(G)=1 and, hence, the two vertices ofGare adjacent. Suppose, then, thatn > 2, and letuandvbe distinct vertices of G; we shall show that there is a walk between them. If u andv are adjacent, there is nothing to do. Otherwise, since
5.2 Paths, Walks and Cycles 137 dG(u)+dG(v)≥2n/2> n−2=#(V (G)\ {u, v}),
the pigeonhole principle guarantees the existence of a vertexw=u, v, adjacent to bothuandv. Therefore, the walk(u, w, v)joinsuandv.
For a fixed graphG, it is immediate to verify that the relation∼inV (G), defined by letting
u∼v⇔ u=v or there exists a walk inGjoininguandv, (5.5) is of equivalence. Also, note that an equivalence class ofV (G)with respect to such a relation is, in particular, a set of vertices ofG.
For the next definition, the reader may find it convenient to review the notion of subgraph induced by a set of vertices, in Problem12, page132.
Definition 5.21 Theconnected componentsof a graphGare the subgraphsG|A ofG, induced by the equivalence classesAofV (G)with respect to the equivalence relation (5.5).
If A is an equivalence class of vertices of G with respect to (5.5), then, in particular, there is a walk between any two distinct vertices inA, so that G|A is a connected graph. On the other hand, ifHis a connected subgraph ofGcontaining G|A, then H = G|A. Indeed, if u ∈ V (H ) and v ∈ A ⊂ V (H ), then the connectedness ofH assures the existence of a walk inH (and hence inG) joining uandv; therefore,u ∈ A, sinceAis an equivalence class of vertices ofGwith respect to the existence of walks. Thus, we haveA ⊂V (H ) ⊂ A, from where it follows thatH = G|A. The above argument allows us to assert that the connected components of a graph are precisely itsmaximal connected subgraphs.
Back to the analysis of the walks in a graph, we collect yet another relevant piece of terminology, which goes back to Euler. In this sense, ifPis a walk in a graphG as in (5.3), we say that{ui−1, ui}, for 1≤i≤k, are the edges ofGtraversedbyP. Definition 5.22 AnEulerian walkin a connected graph is a closed walk which traverses each edge of the graph exactly once. A connected graph isEulerianif it contains an Eulerian walk.
LetGbe an Eulerian graph andP be an Eulerian walk inG, as in (5.3). For an arbitrary vertexuofG, ifk≥ 1 is the number of occurrences ofuinP, we claim thatdG(u)=2k, an even number. This is obvious if all such occurrences ofuare of the formu=ui, with 1≤i < k(for in this caseui−1andui+1are distinct vertices ofG, both adjacent tou); on the other hand, ifu0=u, note thatuk=utoo, forPis closed. Therefore, a necessary condition for a connected graphGto be Eulerian is that all vertices ofGare of even degree. Theorem5.24below guarantees that such condition is also sufficient for the existence of an Eulerian walk. Before we discuss it, we need an important auxiliary result.
Lemma 5.23 IfGis a connected and nontrivial graph in which every vertex has even degree, thenGcontains a closed walk which does not traverse the same edge twice.
Proof Choose a vertex u0 of G and, starting at u0, construct a walk in G by performing the following operation as many times as possible: being at a vertex uk−1ofG, withk≥1, choose a vertexuk ofG, adjacent touk−1and such that the edge{uk−1, uk}has not been chosen yet.
In order to show that the algorithm described above does generate a closed walk in G, assume that, after a certain number of (at least one) operations, we find ourselves in a vertexuk ofG. There are two possibilities:
(i) uk=u0: there is nothing to do, for the closed walk is(u0, u1, . . . , uk).
(ii) uk =u0: suppose that the vertexukhas appeared (with smaller indices) other l times along the performed operations; this used exactly 2l+1 of the edges incident touk (two edges for each of thelprevious occurrence ofuk, and an extra edge to reachuk fromuk−1). However, sinceuk has even degree, there exists at least one edge incident toukand which has not been used yet; hence, the algorithm does not stop atuk.
Finally, since the number of edges inGis finite, the above discussion assures that the algorithm stops atu0and, when it does so, we have succeeded in constructing a closed walk inGwhich does not traverse the same edge twice.
We are now in position to prove the result of Euler alluded to above.
Theorem 5.24 (Euler) A connected and nontrivial graphGis Eulerian if and only if all of its vertices have even degree.
Proof We have already seen, in the paragraph preceding Lemma 5.23, that the condition that all vertices of G have even degree is indeed necessary for the existence of an Eulerian walk. In order to establish the sufficiency, let us make induction on the number of edges ofG.
SinceGis nontrivial, if all of its vertices have even degree, then it has at least three edges; moreover, ifGhas exactly three edges, then it is immediate to prove that it is isomorphic toK3, which is clearly Eulerian.
Now, assume that G has n > 3 edges, and that the theorem is true for all connected graphs with less thannedges and such that all vertices have even degree.
By the previous lemma, we can take inGa closed walkP =(u0, u1, . . . , uk−1, u0), that does not traverse the same edge twice. LetA be the set of edges inP, and H1,. . . , Hl be the nontrivial connected components of G−A (cf. Problem 11, page132). If a vertexuofHi occursj ≥0 times inP, then
dG(u)=dHi(u)+2j,
so thatdHi(u)is even. Since this is true for all indices 1 ≤ i ≤ land all vertices u∈V (Hi), we conclude thatH1, . . . ,Hldo satisfy the hypotheses of the theorem.
5.2 Paths, Walks and Cycles 139 Since eachHi has less edges thanG, the induction hypothesis guarantees the existence of an Eulerian walkPi forHi, for 1 ≤ i ≤ l. At this point, the idea is togluethe Eulerian walksP1, . . . ,PltoPone by one, in a way to get an Eulerian walk forG. To this end, note thatP andP1have at least one vertex in common, sayu. We may assume, without loss of generality, thatP andP1start and end at u(it suffices to change the starting points of both these closed walks, if necessary).
Hence, followingPand subsequentlyP1, we obtain a closed walkP1 inG, which encompasses all of the edges ofP andP1and does not traverse one of them twice.
It now suffices to repeat the above argument morel−1 times, gluingP2toP1to get a closed walkP2, and so on. The closed walkPl, obtained at the end of this process will be an Eulerian walk inG.
The above result, proved by L. Euler in 1735, marks the birth of Graph Theory.
Euler came to it after having been inquired on the possibility of performing a walk along the streets of the prussian city of Kửnigsberg (nowadays the Russian city of Kaliningrad), traversing exactly once each of the seven bridges the city had, at that time, over the Pregel river.
Taking into account that these bridges join two islands of the Pregel to the remaining parts of the city, Euler modelled the problem posed to him as the search for finding, in the graph of Fig.5.3, a walk of the type we refer today as being Eulerian. Although such a graph is not simple (notice the multiple edgesjoining two vertices, a situation that, by the sake of simplicity, we did not allow in our presentation of the theory), a moment’s reflection will easily convince the reader that the previous theorem remains true fornon simple connected graphs. Therefore, this result (actually, the adaptation of the argument for the proof of the necessity part of it, given at the paragraph preceding Lemma5.23) guarantees that the graph of Fig.5.3does not contain an Eulerian walk, for all of its vertices have odd degree.
Back to the general development of the theory, we finish this section by studying the concepts of paths andcycles in graphs, as well as looking at some relevant applications of them.
Definition 5.25 Apathin a graph is a walk with distinct vertices.
Fig. 5.3 Graph representing the bridges of Kửnigsberg
a b c
d
Even though every path is a walk, it is clear that the converse is not true in general, namely, that there are walks which are not paths. Nevertheless, it is not difficult to convince ourselves (cf. Problem 7) that, if a graph contains a walk between two of its vertices, then it also contains a path between them.
Definition 5.26 Ak-cyclein a graphGis a closed walk (u0, u1, . . . , uk−1, u0)
inG, of lengthk≥3 and such that(u0, u1, . . . , uk−1)is a path.
The coming result uses the concept of cycle to characterize bipartite graphs (cf.
Problem16, page133).
Proposition 5.27 A graph Gis bipartite if and only if every cycle in Ghas even length.
Proof Firstly, let us assume thatGis bipartite, with independent sets of verticesV1 andV2. IfC =(u0, u1, u2, . . . , uk−1, u0)is a cycle inG, then the independence of the setsV1andV2guarantees that verticesuiandui+1alternate between the setsV1 andV2, for 0≤i≤k−1 (withuk=u0). In particular, the path(u0, u1, . . . , uk−1) alternates k −1 times between V1 and V2 for, starting from u0, arrive atuk−1. However, since uk−1 andu0 are adjacent, they cannot belong to a single one of the setsV1orV2and, hence,k−1 must be odd. Therefore, the lengthkofCmust be even.
Conversely, assume that every cycle inGhas even length. We use induction on the number of edges to show thatGis bipartite. IfGcontains some cycleC, erase an edge = {u, v}ofC. Since no further cycles are created, all of the cycles of G−are also of even length. Hence, by induction hypothesis,G−is bipartite, with independent sets of verticesV1andV2, say. We shall show thatV1andV2are also independent inG. To this end, note that the pathC−inG−joinsutovand has odd length; since its vertices alternate betweenV1andV2, it follows thatu∈V1 andv∈ V2, or vice-versa. Therefore,V1andV2are also independent inG, so that Gis bipartite too.
The coming definition, due to the nineteenth century Irish astronomer, math- ematician and physicist William R. Hamilton, is, in a certain sense, dualto the definition of Eulerian walk.
Definition 5.28 A hamiltonian cycle in a graph is a cycle that passes through all of the vertices of the graph. A connected graph ishamiltonian if it contains a hamiltonian cycle.
Not every connected graph is hamiltonian; for instance, any graph without cycles is not hamiltonian (for not-so-trivial examples, see Example5.30or Problem21).
The question of the existence or not of hamiltonian cycles in graphs is much more difficult than the corresponding problem for Eulerian walks. Actually, up to now there does not exist a set of simple necessary and sufficient conditions for a
5.2 Paths, Walks and Cycles 141 graph to be hamiltonian. On the other hand, the coming result, due to the Hungarian mathematician of the twentieth century Gabriel Dirac, provides a simple sufficient condition for the existence of hamiltonian cycles in a graph. For its statement, the reader may find it helpful to review the definition of minimum degree of a graph, in (5.4).
Theorem 5.29 (Dirac) IfGis a graph withn≥3vertices and such thatδ(G)≥
n
2, thenGis hamiltonian.
Proof Proposition5.20gives the connectedness ofG. Now, letP =(u0, . . . , uk)be a maximal path inG(i.e., one for which there is no other of greater length). Ifvis a neighbor ofu0not belonging toP, we can changePbyP1=(v, u0, . . . , uk), thus obtaining a path inGbigger thanP, which is a contradiction. Hence,P includes all of the neighbors ofu0and, analogously, all of the neighbors ofuk. In turn, this assures that the length ofPis at least n2.
We first claim that there exists an index 0≤i≤k−1 such thatu0is adjacent to ui+1andui is adjacent touk. In order to show this, letA= {0≤i≤k−1;ui+1∈ NG(u0)}andB = {0 ≤ i ≤ k−1;ui ∈ NG(uk)}. Since all of the vertices in NG(u0)and all of the vertices inNG(uk)are inP, it follows that|A|,|B| ≥ n2. Since|A∪B| ≤k, we then get
|A∩B| = |A| + |B| − |A∪B| ≥n−k >0, forPis a path inGwithk+1 vertices, so thatk+1≤n.
Now, choose 0≤i≤k−1 as in the above claim, and consider the cycle C=(u0, ui+1, ui+2, . . . , uk−1, uk, ui, ui−1, . . . u1, u0).
We claim thatC is hamiltonian. By contradiction, suppose that some vertex ofG, sayv, is not inC. SinceChas more than n2 vertices andvhas at least n2 neighbors, pigeonhole’s principle (applied as in the proof of Proposition5.20) guarantees the existence of a vertexwinCsuch thatwis adjacent tov. Renaming the vertices of C, we can assume that
C=(v0, v1, . . . , vk, v0),
withv0=w. But then,P1=(v, v0, v1, . . . , vk)would be a path inGbigger than P, which is impossible.
The lower bound onδ(G)asked by Dirac’s theorem is the best possible one, in the sense of the following example.
Example 5.30 Letn >1 be odd and letGbe the graph ofnvertices formed by the union of two copies ofK(n+1)/2with a single common vertex, sayu(i.e., take two disjoint copies ofK(n+1)/2, choose one vertex out of each of them and make these two vertices coincide). One clearly hasδ(G) = n−21 < n2. Nevertheless, Gdoes not contain a hamiltonian cycle, for every cycle inGcontainingumust be entirely
contained in one of the copies ofK(n+1)/2which originatedG. Indeed, ifCis such a cycle, thenC−uis a connected subgraph ofG−u, which, in turn is the disjoint union of two copies ofK(n−1)/2; therefore,C−uis contained in a single one of these two copies and, hence, is also contained in a single one of the two copied of K(n+1)/2from which we formedG.
Problems: Sect. 5.2
1. For this problem, recall that ifA=(aij)m×nandB=(bj k)n×parem×nand n×pmatrices with entriesaijandbj k, then the product matrix ofAandB(in this order) isAB=(cik)m×psuch that, for 1≤i≤mand 1≤k≤p, one has
cik = n j=1
aijbj k. (5.6)
This being said, do the following items:
(a) IfM is the adjacency matrix of a graphGof verticesv1, . . . , vn, use the above formula to prove that, fori=j, entry(i, j )ofM2equals the number of distinct paths of length 2 inG, joining verticesvi andvj.
(b) Generalize (5.6), showing that ifA1, . . . ,Akaren×n, withAl=(aijl )n×n, then the product matrix of A1, . . . , Ak (in this order) is A1. . . Ak = (bij)n×n, such that
bij =
l1,...,lk
ail1
1a2l
1l2. . . alk−1
k−2lk−1alk
k−1j,
with the indicesl1, . . . , lk in the above sum varying over all possibilities 1≤l1, . . . , lk ≤n.
(c) Generalize item (a) in the following way: ifMis the adjacency matrix of a graphGof verticesv1, . . . ,vn andk ≥ 1 is an integer, show that entry (i, j )of the matrixMk equals the number of distinct walks of lengthkin G, joining verticesvi andvj.
2. Given a graphGand a vertexuofG, letH=(V;E), whereV is the set of the vertices of all paths inGdeparting fromuandEis the set formed by the edges of these paths. Prove thatHis the connected component ofGcontainingu.
3. Prove that every graph withnvertices and at leastn−1
2
+1 edges is connected.
Give an example of a graph with n vertices and n−1
2
edges which is not connected.
4. SolveProblem2, posed at the beginning of this chapter.
5.2 Paths, Walks and Cycles 143 For the coming problem, you shall need the following fact, to be established in Proposition6.26: given nonzero integersm,nandc, there exist integersx andysuch thatc=mx+nyif and only if gcd(m, n)dividesc.
5. Letmandnbe given naturals andd =gcd(m, n). Prove that the graphG(m, n), described in Problem 14, page 132, has exactly gcd(m, n) = d connected components.
6. Show that if a graphGis disconnected, then its complementG(cf. Problem9, page132) contains a complete bipartite graph with the same set of vertices of G. In particular, conclude that eitherGorGis connected.
7. * If there is a walk between two vertices of a graph, prove that there is also a path between them.
8. Find an Eulerian walk in the graph depicted below:
e d
b a
f g h c
9. Asemi-Eulerian walkin a connected graphGis a walk that starts and ends in distinct vertices ofGand traverses each edge ofGexactly once. Prove thatG has a semi-Eulerian walk if and only if it has exactly two odd degree vertices.
10. Prove that, in every connected graph, two paths whose lengths are the largest possible ones have at least one common vertex.
11. A graphGhasn+2 vertices,u1,u2, . . . ,un,v,w, and satisfies the following conditions:vandware both adjacent tou1, . . . ,un, but not to one another;u1, . . . ,unare pairwise adjacent. For a fixed integer 2≤ k≤ n+1, compute the number of paths of lengthkinG, joiningvtow.
12. If all vertices of a graph have degrees at least 2, prove that the graph contains a cycle.
13. Prove that every 2-regular graph (cf. Problem20, page133) is a cycle.
14. (TT) During a meeting, each one of five mathematicians slept exactly twice.
It is also known that, for each two of those five mathematicians, there was a moment in which both were sleeping. Prove that, at some moment, three of them were sleeping.
15. (IMO) LetGbe a connected graph withnedges. Prove that it is possible to label the edges ofGwith the integers 1 ton, in such a way that the labels attributed to the edges incident at each vertex of degree greater than 1 are relatively prime.
16. * An edgeof a graphGis said to be acutting edgeprovidedG−has more connected components thanG. IfGis a connected graph andis a cutting edge ofG, prove thatG−has exactly two connected components.
For the coming problem, given a digraphG(cf. Problem26, page135) and two of its vertices, sayuandv, we define an (oriented)walkinG, fromuto v, to be a sequence(u0, . . . , uk)of vertices ofGsuch thatu0 = u,uk = v and the edge joiningui andui+1is oriented fromui toui+1, for 0≤i < k. In this case, we say thatkis the length of the walk. Apathis a walk with distinct vertices. Finally, recall that acomplete digraphortournamentis a digraph that turns into a complete graph when we remove the orientation of its edges.
17. In a tournamentG, show that there exists a vertex from which one can reach any other vertex with a path of length at most 2.
18. (TT) In Shvambrania there arencities, each two of them connected by a road.
These roads do not intersect; if necessary, viaducts are used for some of them to overpass others. An evil wizard wants to establish one way directions in each of the roads, so that, if someone leaves a certain city, he/she can no longer return.
Prove that:
(a) The wizard can actually establish such rules.
(b) Whatever the way the wizard chooses to set his rules, there will always be a city from which one can reach any other, and a city from which one cannot leave.
(c) The wizard can execute his intent in exactlyn!distinct ways.
19. (Brazil) Consider ann×nchessboard (n >1 integer), and choose one of itsn2 unit squares, sayc0. Apath6 in the chessboard is a sequence(c0, c1, . . . , cm) of distinct unit squares of the chessboard such that, for each 0 ≤ j < m, squarescj andcj+1share a common edge. Such a path is said to beoptimalif it contains all of then2unit squares of the chessboard. Moreover, we say that a path as above contains anUif, for some 0≤ j ≤m−3, the unit squarescj andcj+3share a common edge. Show that every optimal path contains anU. 20. (Tchecoslovaquia) Prove that, in every connected graph, there exists a vertex
such that the average degree of its neighbors is greater than or equal to the average degree of all vertices of the graph.
21. The purpose of this problem is to prove that Petersen’s graph (cf. Problem15, page133) is not hamiltonian. To this end assume, by contradiction, that such a graph possesses a hamiltonian cycleC. In the notations of Fig.5.4, do the following items:
(a) Prove thatCcontains either two or four of the edges{a, a},{b, b},{c, c}, {d, d}and{e, e}.
(b) If four of the edges in (a) belong toCsuppose, without loss of generality, that{b, b}is the one not belonging to C. Conclude that{a, b},{b, c}, {b, e}and{b, d}are inCand use this to reach a contradiction.
(c) If two of the edges of (a) are inCassume, without loss of generality, that {a, a}is one of them. Conclude that exactly one of the edges {a, c}or
6Note that, in principle, this definition ofpathdoes not coincide with the one given in the text.
Nevertheless, we have chosen to translate it according to the original.