COMPSCI 225:
Discrete Structures in Mathematics and Computer Science

Graphs

The subject of graph theory was initiated by Leonhard Euler. He used it to solve the famous Königsberg bridge problem, which we will discuss later in this chapter.

Graph theory has turned out to be an important tool for solving problems in many fields. For example, one can model the internet by representing webpages as dots and hyperlinks as arrows from one dot to another. Google’s PageRank algorithm was developed by Larry Page and Sergey Brin using ideas from graph theory. Social networks and power infrastructures can also be represented as graphs. By analysing the graph one can determine which nodes have the most influence, or one can evaluate the vulnerability of a network against failure or attack. Facebook and other social network companies use information obtained from the graph as a marketing tool and for offering improved services. For example, graph theory can tell whether a circuit can be implemented on a planar circuit board. It is possible to distinguish between two chemical compounds with the same molecular formula but different structures using graphs. Computer and communication networks are often modelled using graphs. We can determine whether two computers are connected by a communications link using graph models of computer networks. Problems such as finding the shortest tour through a number of cities can be expressed and solved using graph theory, and are a key component of GPS-based navigation systems. There are many more applications.


Introduction to graphs

Graphs are discrete structures formed of dots (called vertices) and lines (called edges or arcs) that run between the vertices.

Examples of graphs

Link copied
Example 5.1.Link copied A simple example of a graph is the following representation of roads between some towns in New Zealand. In such a picture we are not concerned with the roads within the towns, so it suffices to represent each town as a single dot, or vertex. Similarly, we are not concerned with the length of the road, or the exact route it takes across the land. So it suffices to represent the road with a single line.

Note that all the roads are two-way roads (can drive from Auckland to Hamilton or from Hamilton to Auckland along the same road).

Example 5.2.Link copied Now suppose the above graph is not a graph of roads, but of fibre optic cables between some computer data centres in these towns. Each data centre is represented by a vertex, and each optical cable by an edge.

Note that there is at most one cable between two computers in this network and that each cable operates in both directions. In other words, this network can be modeled using a simple graph.

Definition 5.1 A simple graph G=(V,E)G = (V, E) consists of VV , a nonempty set of vertices, and EE , a set of unordered pairs of distinct elements of VV called edges.

Multigraphs

Link copied

Sometimes there are multiple optical cables between computers in a network. This is the case when there is heavy traffic between computers. A network with multiple lines is displayed below. Simple graphs may not be sufficient to model such networks. Instead, multigraphs are used, which consist of vertices and undirected edges between these vertices, with multiple edges between pairs of vertices allowed.

Every simple graph is also a multigraph. However, not all multigraphs are simple graphs, since in a multigraph two or more edges may connect the same pair of vertices.

Example 5.3.Link copied The following is a multigraph. Note that we label the edges, so that cc and dd are both edges from Auckland to Marton, representing different cables from Auckland to Marton data centres.

We cannot use a pair of vertices to specify an edge of a graph when multiple edges are present. This makes the formal definition of multigraphs somewhat complicated.

Definition 5.2 A Multigraph G=(V,E)G = (V, E) consists of a set VV of vertices, a set EE of edges, and a function ff from EE to {{u,v}u,vV,uv}\{ \{u, v\} | u, v \in V , u \not = v\} . The edges e1e_{1} and e2e_{2} are called multiple or parallel edges if f(e1)=f(e2)f(e_{1}) = f(e_{2}) .

Loops and pseudographs

Link copied
Example 5.4.Link copied A graph may contain edges between a vertex and itself. These are called_ loops. The definitions above for graphs and multigraphs do not allow loops, so we define pseudographs _below. The following image has some loops added to the previous graph.

Definition 5.3 A pseudograph G=(V,E)G = (V, E) _consists of a set VV of vertices, a set EE of edges, and a function ff from EE to {{u,v}u,vV} \{ \{u, v\} | u, v \in V\} . An edge is a loop if f(e)={u,u}f (e) = \{u,u\} for some uVu \in V .

We often say ”{u,v}\{u, v\} is an edge of GG ” for a graph G=(V,E)G = (V, E) if there is at least one edge ee with f(e)={u,v}f(e) = \{u, v\} .

To summarize, pseudographs are the most general type of undirected graphs since they may contain loops and multiple edges. Multigraphs are undirected graphs that may contain multiple edges but may not have loops. Finally, simple graphs are undirected graphs with no multiple edges or loops.

Directed graphs

Link copied
Example 5.5.Link copied The optical cables in a computer network may not operate in both directions. For instance, in the following graph, the host computer in Auckland can only send data to Marton.

We use directed graphs to model such networks. The edges of a directed graph are ordered pairs rather than sets. Loops, ordered pairs of the same element, and multiple edges in the same direction between two vertices are not allowed.

Definition 5.4 A directed graph (V,E)(V, E) consists of a set of vertices VV and a set of edges EE that are ordered pairs of elements of VV .

Directed multigraphs

Link copied
Example 5.6.Link copied There may be several one-way fibre cables between two data centres. Such a network is shown next.

Directed graphs are not sufficient for modeling such a network, since multiple edges are not allowed in these graphs. Instead we use directed multigraphs. Loops are not allowed in directed multigraphs.

Definition 5.5 A directed multigraph G=(V,E)G = (V, E) consists of a set VV of vertices, a set EE of edges, _and a function ff from EE to {(u,v)u,vV and uv}\{ (u, v) | u, v \in V \text{ and } u \neq v\} . The edges e1e_{1} and e2e_{2} are multiple edges if f(e1)=f(e2).f (e_{1}) = f(e_{2}).

As before, we will say that (u,v)(u, v) is an edge of G=(V,E)G = (V, E) as long as there is at least one edge ee with f(e)=(u,v)f(e) = (u, v) . We will often interchangeably use the edge ee and the ordered pair (u,v)(u, v) associated to it, unless the identity of individual multiple edges is important.

Directed pseudograph

Link copied
Example 5.7.Link copied There may be a fibre cable inside of a data centre. Such a network is shown next.

Directed multigraphs are not sufficient for modeling such a network, since loops are not allowed in these graphs. Instead we use directed pseudograph.

Definition 5.6 A directed pseudograph G=(V,E)G = (V, E) consists of a set VV of vertices, a set EE of edges, and a function ff from EE to {(u,v)u,vV}.\{ (u, v) | u, v \in V\}. The edges e1e_{1} and e2e_{2} are multiple edges if f(e1)=f(e2).f (e_{1}) = f (e_{2}).

As before, we will say that (u,v)(u, v) is an edge of G=(V,E)G = (V, E) as long as there is at least one edge ee with f(e)=(u,v)f(e) = (u, v) . We will often interchangeably use the edge ee and the ordered pair (u,v)(u, v) associated to it, unless the identity of individual multiple edges is important.


Example 5.8.Link copied We give one more example of a directed pseudograph. Let G=(V,E)G = (V,E) where V={0, 1, 2, 3, 4, 5, 6, 7, 8, 9}V=\{0, \ 1, \ 2, \ 3, \ 4, \ 5, \ 6, \ 7, \ 8, \ 9\} and the set EE of edges is
E=E =
{(0,1),(0,2),(0,3),(2,2),(2,4),(3,4),(3,5),(4,0),\{(0,1), (0,2), (0,3), (2,2), (2,4), (3,4), (3,5), (4,0),
(5,6),(5,8),(6,8),(7,9),(8,6),(8,7),(9,8)}(5,6), (5,8), (6,8), (7,9), (8,6), (8,7), (9,8)\}

Then the graph is pictured below.

Summary of terminology

Link copied

The definitions of the various types of graphs are summarized in the table below.

Graph theory has been applied and developed in a wide range of subjects and applications. Hence, the terminology is not completely standard. When reading other books and webpages you should be careful that the notions “graph” and “multigraph” may have slightly different meanings.

TypeEdgesMultipleEdgesAllowed?LoopsAllowed?SimplegraphUndirectedNoNoMultigraphUndirectedYesNoPseudographUndirectedYesYesDirectedgraphDirectedNoNoDirectedmultigraphDirectedYesNoDirectedpseudographDirectedYesYes\begin{array}{|c|c|c|c|} Type & Edges & Multiple Edges Allowed? & Loops Allowed?\\\hline Simple graph & Undirected & No & No\\ Multigraph & Undirected & Yes & No \\ Pseudograph & Undirected & Yes & Yes\\ Directed graph & Directed & No & No\\ Directed multigraph & Directed & Yes & No \\ Directed pseudograph & Directed & Yes & Yes\\ \end{array}
TypeEdgesMultiple Edges Allowed?Loops Allowed?
Simple graphUndirectedNoNo
MultigraphUndirectedYesNo
Pseudograph UndirectedYesYes
Directed graphDirectedNoNo
Directed multigraphDirectedYesNo
Directed pseudographDirectedYesYes

Basic terminology

We introduce some basic vocabulary used in graph theory.

Terminology on vertices and edges

Link copied

Definition 5.7 Two vertices uu and vv in an undirected graph GG are called adjacent (or neighbors) in GG if {u,v}\{u, v\} is an edge of GG . If e={u,v}e = \{u, v\} , the edge ee is called incident with the vertices uu and vv . The edge ee is also said to connect uu and vv . The vertices uu and vv are called endpoints _of the edge {u,v}\{u, v\} .

Degree

Link copied

To keep track of how many edges are incident to a vertex, we make the following definition.

Definition 5.8 The degree of a vertex in an undirected graph is the number of edges incident with it, except that a loop at a vertex contributes twice to the degree of that vertex. The degree of the vertex vv is denoted by deg(v)\deg(v) .


Example 5.9.Link copied What are the degrees of the vertices in the graphs GG and HH ?

The handshaking theorem

Link copied

Every edge is incident with exactly two (possibly equal) vertices. Hence, the sum of the degrees of the vertices is twice the number of edges. This result is sometimes called the Handshaking Theorem, because of the analogy between an edge having two endpoints and a handshake involving two hands.

Theorem 5.1 [The Handshaking Theorem] Let G=(V,E)G = (V,E) be an undirected graph with E|E| edges. Then

2E=vVdeg(v)2|E| = \sum_{v\in V} \deg(v)

(Note this applies even if multiple edges and loops are present.)

Proof: See lecture.


Example 5.10.Link copied How many edges are there in a graph with 10 vertices each of degree 6?

Theorem 5.1 shows that the sum of the degrees of the vertices of an undirected graph is even. This simple fact has many consequences, one of which is given as Theorem 5.2.

Theorem 5.2 An undirected graph has an even number of vertices of odd degree.

Proof: See lecture.


Definition 5.9 The degree sequence of a graph GG is the sequence (n0,n1,n2,,nk)(n_0,n_1,n_2,\dots,n_k) , where nin_i is the number of vertices of degree ii , nk0n_k\ne 0 , and GG does not have any vertices of degree greater than kk .


Example 5.11.Link copied What are the degree sequences of the graphs GG and HH ?

Terminology for directed graphs

Link copied

We now give some useful terminology for graphs with directed edges.

Definition 5.10 When (u,v)(u, v) is an edge of the graph GG with directed edges, uu is said to be adjacent to vv and vv is said to be adjacent from uu . The vertex uu is called the initial vertex of (u,v)(u, v) , and vv is called the terminal or end vertex of (u,v)(u, v) . The initial vertex and terminal vertex of a loop are the same. We say an edge (u,v)(u,v) is outgoing from uu and ingoing to vv .

In-degree and out-degree

Link copied

Definition 5.11 In a graph with directed edges the in-degree of a vertex vv , denoted by deg(v)\deg^{-}(v) , is the number of edges with vv as their terminal vertex. The out-degree of vv , denoted by deg+(v)\deg^{+}(v) , is the number of edges with vv as their initial vertex. (Note that a loop at a vertex contributes 1 to both the in-degree and the out-degree of this vertex.)


Example 5.12.Link copied Find the in-degree and out-degree of each vertex in the graph G with directed edges shown below.

Since each edge has an initial vertex and a terminal vertex, the sum of the in-degrees and the sum of the out-degrees of all vertices in a graph with directed edges are the same. Both of these sums are the number of edges in the graph. This result is stated as the following theorem.


Theorem 5.3 _Let G=(V,E)G = (V, E) be a graph with directed edges. Then

vVdeg(v)=vVdeg+(v)=E.\sum_{v\in V}\deg^{-}(v) = \sum_{v\in V} \deg^{+}(v) = |E|.

Underlying graph

Link copied

There are many properties of a graph with directed edges that do not depend on the direction of its edges. Consequently, it is often useful to ignore these directions. The undirected graph that results from ignoring directions of edges is called the underlying undirected graph. A graph with directed edges and its underlying undirected graph have the same number of edges.

We will now introduce several classes of simple graphs. These graphs are often used as examples and arise in many applications.

Complete graphs

Link copied

The complete graph on nn vertices, denoted by KnK_{n} , is the simple graph that contains exactly one edge between each pair of distinct vertices. The graphs KnK_{n} , for n=1,2,3,4,5,6n = 1, 2, 3, 4, 5, 6 are displayed below.

Cycle graphs

Link copied

The cycle_ graph Cn,n3C_{n}, n\geq 3 , consists of n vertices v1,v2,,vnv_{1}, v_{2}, \ldots, v_{n} and edges {v1,v2,},{v2,v3,},,{vn1,vn}\{v_{1}, v_{2}, \}, \{v_{2}, v_{3}, \}, \ldots, \{v_{n-1}, v_{n}\} and {vn,v1,}.\{v_{n}, v_{1}, \}. The cycle graphs C3,C4,C5C_{3}, C_{4}, C_{5} , and C6C_{6} are displayed below.


Wheel graphs

Link copied

We obtain the wheel graph WnW_{n} when we add an additional vertex to the cycle CnC_{n} , for n3n \geq 3 , and connect this new vertex to each of the nn vertices in CnC_{n} by new edges. The wheel graphs W3,W4,W5W_{3}, W_{4}, W_{5} , and W6W_{6} are displayed below.

nn -Cubes

The nn -cube, denoted by QnQ_{n} is the graph that has vertices representing the 2n2^{n} bit strings of length nn . Two vertices are adjacent if and only if the bit strings that they represent differ in exactly one bit position. The graphs Q1,Q2Q_{1}, Q_{2} , and Q3Q_{3} are displayed below.

Bipartite graphs

Link copied

Sometimes a graph has the property that its vertex set can be divided into two disjoint subsets such that each edge connects a vertex in one of these subsets to a vertex in the other subset. For example, consider the graph representing all the students in this class and the set of courses they are taking. We draw an edge between a student and a course if the student is taking that course. The vertex set is the union SCS \cup C where SS is the set of students and CC is the set of courses.

Definition 5.12 A simple graph GG is called bipartite if its vertex set VV can be partitioned into two disjoint nonempty sets V1V_{1} and V2V_{2} such that every edge in the graph connects a vertex in V1V_{1} and a vertex in V2V_{2} (so that no edge in GG connects either two vertices in V1V_{1} or two vertices in V2V_{2} ).


Example 5.13.Link copied Show that C6C_{6} is bipartite.

Example 5.14.Link copied Show that K3K_{3} is not bipartite.

Example 5.15.Link copied Are the graphs GG and HH displayed below bipartite?

Complete bipartite graphs

Link copied

The complete bipartite graph Km,nK_{m,n} is the graph that has its vertex set partitioned into two subsets of mm and nn vertices, respectively. There is an edge between two vertices if and only if one vertex is in the first subset and the other vertex is in the second subset.

Example 5.16.Link copied The complete bipartite graphs K2,3K_{2,3} and K3,3K_{3,3} are displayed below.

Subgraphs

Link copied

Sometimes we need only part of a graph to solve a problem. For instance, we may care only about one part of a large computer network, such as the part that involves the data centres in Auckland, Hamilton, Wellington, and Christchurch. We can ignore the other centres and cables. In the graph model we remove the vertices corresponding to the computer centres other than the four of interest, and we remove all edges incident with any vertex that was removed.

When edges and vertices are removed from a graph, without removing endpoints of any remaining edges, a smaller graph is obtained. Such a graph is called a subgrap of the original graph.


Definition 5.13 A subgraph of a graph G=(V,E)G = (V, E) is a graph H=(W,F)H = (W, F) where WVW \subseteq V and FEF \subseteq E .

Notice that, in the definition of a subgraph, we must remove any edges which have had one of their endpoints removed. This does not mean that we may not also remove some of the other edges. For example, for any graph G=(V,E)G=(V,E) , the graph H=(V,)H=(V,\varnothing) counts as a (rather uninteresting) example of a subgraph.

For example, the graph below has C5C_5 as a subgraph, because we can delete the “inside” vertices and edges to have just a C5C_5 left over.


Note that any graph GG is “trivially” a subgraph of itself, as we can just delete “nothing” from GG and have GG left over.


Example 5.17.Link copied Let GG be the graph shown below. Which of the graphs H1H_1 , H2H_2 , H3H_3 are subgraphs of G?

Union of two graphs

Link copied

Two or more graphs can be combined in various ways. The new graph that contains all the vertices and edges of these graphs is called the union of the graphs. We will give a more formal definition for the union of two simple graphs.


Definition 5.14 The union _of two simple graphs G1=(V1,E1)G_{1} = (V_{1},E_{1}) and G2=(V2,E2)G_{2} = (V_{2}, E_{2}) is the simple graph with vertex set V1V2V_{1} \cup V_{2} and edge set E1E2.E_{1} \cup E_{2}. The union of G1G_{1} and G2G_{2} is denoted by G1G2G_{1} \cup G_{2} . (Note: we assume V1V2=V_1 \cap V_2 = \emptyset .)


Example 5.18.Link copied Find the union of the graphs G1G_{1} and G2G_{2} shown below.

Representing graphs

There are many useful ways to represent graphs. When working with graphs, it is helpful to be able to choose the most convenient representation. In this section we will show how to represent graphs in several different ways.

Sometimes, two graphs have exactly the same structure, in the sense that there is a one-to-one correspondence between their vertex sets that preserves edges. In such a case, we say that the two graphs are isomorphic. Determining whether two graphs are isomorphic is an important problem of graph theory.

Adjacency lists

Link copied

One way to represent a graph without multiple edges is to list all the edges of this graph. Another way to represent a graph with no multiple edges is to use adjacency lists, which specify the vertices that are adjacent to each vertex of the graph.

Example 5.19.Link copied Use adjacency lists to describe the simple graph given below.

Example 5.20.Link copied Represent the directed graph shown below by listing all the vertices that are the terminal vertices of edges starting at each vertex of the graph.

Adjacency matrices

Link copied

Carrying out graph algorithms using the representation of graphs by lists of edges, or by adjacency lists, can be cumbersome if there are many edges in the graph. To simplify computation, graphs can be represented using matrices. Two types of matrices commonly used to represent graphs will be presented here. One is based on the adjacency of vertices, and the other is based on incidence of vertices and edges.

Suppose that G=(V,E)G = (V, E) is a simple graph where V=n|V| = n . Suppose that the vertices of GG are listed as v1,v2,,vnv_{1}, v_{2}, \ldots, v_{n} . The adjacency matrix AA (or AGA_{G} ) of G with respect to this listing of the vertices, is the n×nn \times n zero-one matrix with 1 as its (i,j)(i, j) th entry when viv_{i} and vjv_{j} are adjacent, and 0 as its (i,j)(i, j) th entry when they are not adjacent. In other words, if its adjacency matrix is A=[aij]A = [a_{ij}] , then

a_{ij}=\left\{\begin{array}{ll} 1 & if \{v_{i},v_{j}, \} \text {is an edge of} G\\ 0 & otherwise\\ \end{array}\right}

Note that an adjacency matrix of a graph is based on the ordering chosen for the vertices. Hence, there are potentially as many as n!n! different adjacency matrices for a graph with nn vertices, since there are n!n! different orderings of nn vertices. However, once a listing v1,v2,,vnv_{1}, v_{2}, \ldots, v_{n} of the vertices has been decided, the adjacency matrix is uniquely determined by the graph.

The adjacency matrix of a simple graph is symmetric, meaning that aij=ajia_{ij} = a_{ji} , since both of these entries are 1 when viv_{i} and vjv_{j} are adjacent, and both are 0 otherwise. Furthermore, since a simple graph has no loops, each entry aiia_{ii} , i=1,2,3,,ni = 1, 2, 3, \ldots, n , s 0.

Example 5.21.Link copied Use an adjacency matrix to represent the graph shown below.

Example 5.22.Link copied Draw a graph with the adjacency matrix
[0110100110010110].\left[\begin{array}{cccc} 0 &1 &1 &0\\ 1 &0 &0 &1\\ 1 &0 &0 &1\\ 0 &1 &1 &0\\ \end{array}\right].

Adjacency matrices can also be used to represent undirected graphs with loops and with multiple edges. A loop at the vertex viv_{i} is represented by a 1 at the (i,i)(i, i) th position of the adjacency matrix. When multiple edges are present, the adjacency matrix is no longer a zero-one matrix, since the (i,j)(i, j) th entry of this matrix equals the number of edges that are associated to {vi,vj}\{v_{i}, v_{j}\} . All undirected graphs, including multigraphs and pseudographs, have symmetric adjacency matrices.

Example 5.23.Link copied Use an adjacency matrix to represent the pseudograph shown below.

The adjacency matrix for a directed graph does not have to be symmetric, since there may not be an edge from vjv_j to viv_i when there is an edge from viv_i to vjv_j . Adjacency matrices can also be used to represent directed multigraphs. Again, such matrices are not zero-one matrices when there are multiple edges in the same direction connecting two vertices In the adjacency matrix for a directed multigraph, aija_{ij} equals the number of edges that are associated to (vi,vj)(v_{i}, v_{j}) .


Connectivity, paths and circuits

Many problems can be studied by considering paths formed by traveling along the edges of graphs. For instance, the problem of determining whether a message can be sent between two computers using intermediate links can be studied with a graph model.

Paths and circuits

Link copied

We begin by defining the basic terminology of paths and circuits.

Definition 5.15

When it is not necessary to distinguish between multiple edges, we will denote a path e1,e2,,ene_{1}, e_{2}, \ldots, e_{n} where f(ei)={xi1,xi}f (e_{i}) = \{x_{i-1}, x_{i}\} for i=1,2,,ni = 1, 2, \ldots, n by its vertex sequence x0,x1,,xnx_{0}, x_{1}, \ldots, x_{n} . This notation identifies a path only up to the vertices it passes through. There may be more than one path that passes through this sequence of vertices.


Example 5.24 _In the simple graph given below, show that a,d,c,f,ea, d, c, f, e is a path of length 4. Why is d,e,c,ad, e, c, a is not a walk? Show that b,c,f,e,b,a,e,bb, c, f, e, b, a, e, b is a circuit but not a cycle. What is the length of the circuit b,c,f,e,b,a,e,bb, c, f, e, b, a, e, b ? Why a,b,e,d,a,ba, b, e, d, a, b is not a path?


Theorem 5.4 Let G=(V,E)G = (V,E) be a graph and let u,vVu, v \in V . If there is a walk from uu to vv then there is a path from uu to vv .

Proof: See lecture.


Theorem 5.5 Let G=(V,E)G = (V,E) be a graph and let u,v,wVu, v, w \in V . If there is a walk from uu to vv and a walk from vv to ww then there is a walk from uu to ww .

Proof: See lecture.

Connectedness in undirected graphs

Link copied

A fundamental problem is to determine whether or not a network has the property that every pair of nodes can communicate with one another. For example, in a network of computers or data centres, two devices can communicate if there is a a cable between them or if their messages can be sent through one or more intermediate computers. If the network is represented by a graph, where edges represent the communication links, this problem becomes: When is there always a walk between two vertices in the graph?

Definition 5.16 An undirected graph is called connected if there is a walk between every pair of distinct vertices of the graph.

For this definition we always allow a walk of length 00 from a vertex to itself.

Thus, any two computers in the network can communicate if and only if the graph of this network is connected.


Example 5.25.Link copied Is the graph GG shown below connected? Why or why not? Is the graph HH shown below connected? Why or why not?

Theorem 5.6 There is a path between every pair of distinct vertices of a connected undirected graph.

Proof: See lecture.

Components

Link copied

A graph that is not connected is the union of two or more connected graphs, each pair of which has no vertex in common. These disjoint connected graphs are called the connected components of the graph.

Example 5.26.Link copied What are the connected components of the graph GG shown below?

Paths and circuits in directed multigraphs

Link copied

Definition 5.17

When it is not necessary to distinguish between multiple edges, we will denote a path e1,e2,,ene_{1}, e_{2}, \ldots, e_{n} where f(e1)=(xi1,xi)f (e_{1}) = (x_{i-1}, x_{i}) for i=1,2,,ni = 1, 2, \ldots, n by its vertex sequence x0,x1,,xnx_{0}, x_{1}, \ldots, x_{n} . The notation identifies a path only up to the vertices it passes through. There may be more than one path that passes through this sequence of vertices.

Connectedness in directed graphs

Link copied

There are two notions of connectedness in directed graphs, depending on whether the directions of the edges are considered. Again we declare that a vertex is always strongly connected with itself (by a walk of length zero).


Definition 5.18 Two vertices a,ba, b in a directed graph are strongly connected if there is a walk from aa to bb and a walk from bb to aa .

A directed graph is strongly connected if there is a walk from aa to bb and a walk from bb to aa whenever aa and bb are vertices in the graph.

For a directed graph to be strongly connected there must be a sequence of directed edges from any vertex in the graph to any other vertex. A directed graph can fail to be strongly connected but still be in “one piece.” To make this precise, the following definition is given.


Definition 5.19 A directed graph is weakly connected if there is a walk between any two vertices in the underlying undirected graph.

That is, a directed graph is weakly connected if and only if there is always a walk between two vertices when the directions of the edges are disregarded. Clearly, any strongly connected directed graph is also weakly connected.


Theorem 5.7 Let G=(V,E)G = (V,E) be a directed graph.

  1. Every vertex is strongly connected to itself._
  2. Let u,vVu, v \in V . If uu is strongly connected to vv then vv is strongly connected to uu .
  3. Let u,v,wVu, v, w \in V . If uu is strongly connected to vv and vv is strongly connected to ww then uu is strongly connected to ww .

Proof: See lecture.


Example 5.27 Are the directed graphs GG and HH shown below strongly connected? Are they weakly connected?


Isomorphism of graphs

We often need to know whether it is possible to draw two graphs in the same way. For instance, in chemistry, graphs are used to model compounds. Different compounds can have the same molecular formula but can differ in structure. Such compounds will be represented by graphs that cannot be drawn in the same way. The graphs representing previously known compounds can be used to determine whether a supposedly new compound has been studied before.

Isomorphic graphs

Link copied

Definition 5.20 The simple graphs G1=(V1,E1)G_{1} = (V_{1}, E_{1} ) and G2=(V2,E2)G_{2} = (V_{2}, E_{2}) are isomorphic if there is a one-to-one and onto function h:V1V2h : V_{1} \to V_{2} with the property that aa and bb are adjacent in G1G_{1} if and only if h(a)h(a) and V2” /> with the property that aa and bb are adjacent in G1G_{1} if and only if h(b)h (b) are adjacent in G2G_{2} , for all aa and bb in V1V_{1} . Such a function hh is called an_ isomorphism.

In other words, when two simple graphs are isomorphic, there is a one-to-one correspondence between vertices of the two graphs that preserves the adjacency relationship.


Example 5.28.Link copied Show that the graphs G=(V,E)G = (V, E) and H=(W,F)H = (W, F) , displayed below, are isomorphic.

Invariant properties

Link copied

It is often difficult to determine whether two simple graphs are isomorphic. There are n!n! possible one-to-one correspondences between the vertex sets of two simple graphs with nn vertices. Testing each such correspondence to see whether it preserves adjacency and nonadjacency is impractical if nn is at all large.

However, we can often show that two simple graphs are not isomorphic by showing that they do not share a property that isomorphic simple graphs must both have. Such a property is called an invariant with respect to isomorphism of simple graphs. For instance:

Number of vertices and edges in isomorphic graphs

Link copied

The number of vertices, the number of edges, and the degrees of the vertices are all invariants under isomorphism. If any of these quantities differ in two simple graphs, these graphs cannot be isomorphic.

However, when these invariants are the same, it does not necessarily mean that the two graphs are isomorphic. There are no useful sets of invariants currently known that can be used to determine whether simple graphs are isomorphic.


Example 5.29.Link copied Determine whether the graphs GG and HH shown below are isomorphic.

To show that a function hh from the vertex set of a graph GG to the vertex set of a graph HH is an isomorphism, we need to show that hh preserves edges.


Example 5.30.Link copied Determine whether the graphs GG and HH displayed below are isomorphic.

Paths and isomorphism

Link copied

There are several ways that walks and cycles can help determine whether two graphs are isomorphic. For example, the existence of a cycle of a particular length is a useful invariant that can be used to show that two graphs are not isomorphic. In addition, walks can be used to construct mappings that may be isomorphisms.

Example 5.31.Link copied Determine whether the graphs shown below are isomorphic.

We have shown how the existence of a type of walk, namely, a cycle of a particular length, can be used to show that two graphs are not isomorphic. We can also use walks to find mappings that are potential isomorphisms.

Example 5.32.Link copied Determine whether the graphs shown below are isomorphic.

Euler circuits and walks

We now tell a famous story in the history of graph theory. Back in the 18th century, the town of Königsberg was part of Prussia (it is now called Kaliningrad and is part of the Russian republic). The town was divided into four sections by the Pregel River. These four sections included the two regions on the banks of the Pregel, Kneiphof Island, and the region between the two branches of the Pregel. In the 18th century seven bridges connected these regions. The image below (from the MacTutor website) depicts these regions and bridges.

The people in the town enjoyed walking through the town on Sundays. They wondered whether it was possible to start at some location in the town, travel across all the bridges without crossing any bridge twice, and return to the starting point.

The Swiss mathematician Leonhard Euler showed that no such Sunday stroll exists. His solution was published in 1736, and is considered to be the birth of graph theory. Euler studied this problem using the multigraph obtained when the four regions are represented by vertices and the bridges are represented by edges. This multigraph is shown below.

Euler circuit and walks

Link copied

The problem of traveling across every bridge without crossing any bridge more than once can be rephrased in terms of this model. The question becomes: Is there a circuit in this multigraph that contains every edge exactly once? (Note that this circuit is required to visit every edge, so it must visit vertices of degree >2> 2 more than once.) This may seem an artificial problem, but it has applications in scheduling postal delivery routes and trash collection services.

Definition 5.21 An Euler circuit in a graph GG is a circuit containing every edge of GG exactly once. An Euler walk in GG is a walk containing every edge of GG exactly once.


Example 5.33.Link copied Which of the undirected graphs below have an Euler circuit? Of those that do not, which have an Euler walk?

Example 5.34.Link copied Which of the directed graphs below have an Euler circuit? Of those that do not, which have an Euler walk?

Necessary and sufficient condition for Euler circuits

Link copied

There are simple criteria for determining whether a multigraph has an Euler circuit or an Euler walk. Euler discovered them when he solved the famous Königsberg bridge problem. We will assume that all graphs discussed in this section have a finite number of vertices and edges.

What can we say if a connected multigraph has an Euler circuit? What we can show is that every vertex must have even degree.

Example 5.35.Link copied Solve the Königsberg bridge problem.

Is this necessary condition for the existence of an Euler circuit also sufficient? That is, must an Euler circuit exist in a connected multigraph if all vertices have even degree? The next result is one of the first big theorems in graph theory.


Theorem 5.8 A connected multigraph has an Euler circuit if and only if each of its vertices has even degree.

The algorithm below gives the constructive procedure for finding Euler circuits.

procedure EulerEuler (G:G: connected multigraph with all vertices of even degree)

C:=C:= a circuit in GG beginning at an arbitrarily chosen vertex with edges successively added to form a walk that returns to this vertex.

H:=GH := G with the edges of CC removed

while HH has edges

begin

end CC is an Euler circuit


Example 5.36.Link copied Many puzzles ask you to draw a picture in a continuous motion, without lifting the pencil off the page, so that no part of the picture is retraced. We can solve such puzzles using Euler circuits and walks. For example, can_ Mohammed’s scimitars, _shown below, be drawn in this way, where the drawing begins and ends at the same point?

Necessary and sufficient condition for Euler walks

Link copied

Theorem 5.9 A connected multigraph has an Euler walk but not an Euler circuit if and only if it has exactly two vertices of odd degree.


Example 5.37.Link copied Which graphs shown below have an Euler walk?

Example 5.38.Link copied Returning to 18th-century Königsberg, is it possible to start at some point in the town, travel across all the bridges exactly once, and end up at some other point in town?

Example 5.39.Link copied A domino is a rectangle divided into two squares with each square numbered one of 0,1,,60,1,\dots, 6 . Two squares on a single domino can have the same number. Show that the twenty-one distinct dominoes can be arranged in a circle so that touching dominoes have adjacent squares with identical numbers. (Hint : Consider the complete graph K7K_7 with vertices labeled 0,1,,60,1,\dots,6 . This has a Euler circuit since each of its vertices has degree 6.)

Hamilton paths and cycles

We have developed necessary and sufficient conditions for the existence of walks and circuits that contain every edge of a multigraph exactly once. Can we do the same for walks and circuits that contain every vertex of the graph exactly once?

Definition 5.22 A path x0,x1,,xn1,xnx_{0}, x_{1}, \ldots, x_{n-1}, x_{n} in the graph G=(V,E)G = (V, E) is called a Hamilton path if

V={x0,x1,,xn1,xn}.V = \{x_{0}, x_{1}, \ldots, x_{n-1}, x_{n}\}.

A cycle

x0,x1,,xn1,xn,x0x_{0}, x_{1}, \ldots, x_{n-1}, x_{n}, x_{0}

(with n>1n > 1 ) in a graph G=(V,E)G = (V, E) is called a Hamilton cycle if x0,x1,,xn1,xnx_{0}, x_{1}, \ldots, x_{n-1}, x_{n} is a Hamilton path.

Hamilton's puzzle

Link copied

This terminology comes from a puzzle invented in 1857 by the Irish mathematician Sir William Rowan Hamilton. Hamilton’s puzzle consisted of a wooden dodecahedron (a polyhedron with 12 regular pentagons as faces, as shown below, with a peg at each vertex of the dodecahedron, and string). The 20 vertices of the dodecahedron were labeled with different cities in the world. The object of the puzzle was to start at a city and travel along the edges of the dodecahedron (see the following picture), visiting each of the other 19 cities exactly once, and end back at the first city. The circuit traveled was marked off using the strings and pegs.

Example 5.40.Link copied Since we cannot supply each student with a wooden solid with pegs and string, we will consider the equivalent question: Is there a circuit in the graph shown below that passes through each vertex exactly once? This solves the puzzle since this graph is isomorphic to the graph consisting of the vertices and edges of the dodecahedron.

Example 5.41.Link copied Which of the simple graphs below have a Hamilton cycle or, if not, a Hamilton path?

Determining whether a graph contains a Hamilton cycle

Link copied

Is there a simple way to determine whether a graph has a Hamilton cycle or path? At first, it might seem that there should be an easy way to determine this, since there is a simple way to answer the similar question of whether a graph has an Euler circuit.

Surprisingly, there are no known simple necessary and sufficient criteria for the existence of Hamilton cycles. However, many theorems are known that give sufficient conditions for the existence of Hamilton cycles. Also, certain properties can be used to show that a graph has no Hamilton cycle.

Example 5.42.Link copied Show that neither graph displayed below has a Hamilton cycle.

Example 5.43.Link copied Show that KnK_{n} has a Hamilton cycle whenever n3n \geq 3 .

The traveling salesperson problem

Link copied

Suppose the drawing below is a map showing four cities and the distances in kilometers between them. Suppose that a salesperson must visit each city exactly once, starting and ending in city A. Which route from city to city will minimize the total distance that must be traveled?


This problem can be solved by writing all possible Hamiltonian circuits starting and ending at A and calculating the total distance traveled for each.

Thus either route ABCDA or ADCBA gives a minimum total distance of 125 kilometers.

The general traveling salesperson problem involves finding a Hamiltonian circuit to minimize the total distance traveled for an arbitrary graph with nn vertices in which each edge is marked with a distance. One way to solve the general problem is to use the above method. Write down all Hamiltonian circuits starting and ending at a particular vertex, compute the total distance for each, and pick one for which this total is minimal. However, even for medium-sized values of nn this method is impractical. At present, there is no known algorithm for solving the general traveling salesperson problem that is more efficient. However, there are efficient algorithms that find ‘pretty good’ solutions, that is, circuits that, while not necessarily having the least possible total distance, have smaller total distances than most other Hamiltonian circuits.