Chapter10 Graphs
Chapter10 Graphs
Chapter 10
Copyright © McGraw-Hill Education. All rights reserved. No reproduction or distribution without the prior written consent of McGraw-Hill Education.
Chapter Summary
Graphs and Graph Models
Graph Terminology and Special Types of Graphs
Representing Graphs and Graph Isomorphism
Connectivity
Euler and Hamiltonian Graphs
Shortest-Path Problems (not currently included in
overheads)
Planar Graphs (not currently included in overheads)
Graph Coloring (not currently included in overheads)
Graphs and Graph Models
Section 10.1
Section Summary
Introduction to Graphs
Graph Taxonomy
Graph Models
Graphs
Definition: A graph G = (V, E) consists of a nonempty set V of vertices (or nodes) and a set E of
edges. Each edge has either one or two vertices associated with it, called its endpoints. An edge is
said to connect its endpoints.
Example: a b
This is a graph
with four
vertices and five
edges.
d c
Remarks:
The graphs we study here are unrelated to graphs of functions studied in Chapter 2.
We have a lot of freedom when we draw a picture of a graph. All that matters is the connections made by the edges, not the particular
geometry depicted. For example, the lengths of edges, whether edges cross, how vertices are depicted, and so on, do not matter
A graph with an infinite vertex set is called an infinite graph. A graph with a finite vertex set is called a finite graph. We (following the
text) restrict our attention to finite graphs.
Some Terminology
In a simple graph each edge connects two different vertices and no two
edges connect the same pair of vertices.
Multigraphs may have multiple edges connecting the same two
vertices. When m different edges connect the vertices u and v, we say
that {u,v} is an edge of multiplicity m.
An edge that connects a vertex to itself is called a loop.
A pseudograph may include loops, as well as multiple edges connecting
the same pair of vertices.
a b
Example:
This is a directed graph with
three vertices and four edges.
c
A directed multigraph may have multiple directed edges. When there
are m directed edges from the vertex u to the vertex v, we say that
(u,v) is an edge of multiplicity m.
Example:
a b
In this directed multigraph the
multiplicity of (a,b) is 1 and the
multiplicity of (b,c) is 2.
c
Graph Models:
Computer Networks
When we build a graph model, we use the appropriate type of graph to
capture the important features of the application.
We illustrate this process using graph models of different types of
computer networks. In all these graph models, the vertices represent
data centers and the edges represent communication links.
To model a computer network where we are only concerned whether
two data centers are connected by a communications link, we use a
simple graph. This is the appropriate type of graph when we only care
whether two data centers are directly linked (and not how many links
there may be) and all communications links work in both directions.
Graph Models:
Computer Networks (continued)
• To model a computer network
where we care about the number
of links between data centers, we
use a multigraph.
Example: An
influence graph
Solution:
G: deg(a) = 2, deg(b) = deg(c) = deg(f ) = 4, deg(d ) = 1,
deg(e) = 3, deg(g) = 0.
N(a) = {b, f }, N(b) = {a, c, e, f }, N(c) = {b, d, e, f }, N(d) = {c},
N(e) = {b, c , f }, N(f) = {a, b, c, e}, N(g) = .
H: deg(a) = 4, deg(b) = deg(e) = 6, deg(c) = 1, deg(d) = 5.
N(a) = {b, d, e}, N(b) = {a, b, c, d, e}, N(c) = {b},
N(d) = {a, b, e}, N(e) = {a, b ,d}.
Degrees of Vertices
Theorem 1 (Handshaking Theorem): If G = (V,E) is an undirected
graph with m edges, then
Proof:
Each edge contributes twice to the degree count of all vertices. Hence,
both the left-hand and right-hand sides of this equation equal twice
the number of edges.
Think about the graph where vertices represent the people at a party and
an edge connects two people who have shaken hands.
Handshaking Theorem
We now give two examples illustrating the usefulness of the
handshaking theorem.
Some local area networks use a star topology, which is a complete bipartite graph K1,n ,as shown in (a).
All devices are connected to a central control device.
Other local networks are based on a ring topology, where each device is connected to exactly two
others using Cn ,as illustrated in (b). Messages may be sent around the ring.
Others, as illustrated in (c), use a Wn – based topology, combining the features of a star topology and a
ring topology.
Various special graphs also play a role in parallel processing where processors need to be
interconnected as one processor may need the output generated by another.
The n-dimensional hypercube, or n-cube, Qn, is a common way to connect processors in parallel, e.g., Intel
Hypercube.
Another common method is the mesh network, illustrated here for 16
processors.
Bipartite Graphs
Definition: A simple graph G is bipartite if V can be partitioned into two
disjoint subsets V1 and V2 such that every edge connects a vertex in V1 and a
vertex in V2. In other words, there are no edges which connect two vertices
in V1 or in V2.
H is not bipartite
G is since if we color a
bipartite red, then the
adjacent vertices f
and b must both
be blue.
Bipartite Graphs (continued)
Example: Show that C6 is bipartite.
Solution: We can partition the vertex set into V1 = {v1, v3,
v5} and V2 = {v2, v4, v6} so that every edge of C6 connects a vertex in V1
and V2 .
Definition: Let G = (V, E) be a simple graph. The subgraph induced by a subset W of the
vertex set V is the graph (W,F), where the edge set F contains an edge in E if and only if
both endpoints are in W.
Marriage - vertices represent the men and the women and edges link a a
man and a woman if they are an acceptable spouse. We may wish to find
the largest number of possible marriages.
Example:
Representing Graphs and
Graph Isomorphism
Section 10.3
Section Summary
Adjacency Lists
Adjacency Matrices
Incidence Matrices
Isomorphism of Graphs
Representing Graphs:
Adjacency Lists
Definition: An adjacency list can be used to represent
a graph with no multiple edges by specifying the
vertices that are adjacent to each vertex of the graph.
Example:
Example:
Representation of Graphs: Adjacency
Matrices
Definition: Suppose that G = (V, E) is a simple graph
where |V| = n. Arbitrarily list the vertices of G as
v1, v2, … , vn. The adjacency matrix AG of G, with
respect to the listing of vertices, is the n × n zero-one
matrix with 1 as its (i, j)th entry when vi and vj are
adjacent, and 0 as its (i, j)th entry when they are not
adjacent.
In other words, if the graphs adjacency matrix is
AG = [aij], then
Adjacency Matrices (continued)
Example: When a graph is sparse, that
is, it has few edges relatively
to the total number of
possible edges, it is much
The ordering of more efficient to represent
vertices is a, b, c, d. the graph using an
adjacency list than an
adjacency matrix. But for a
The ordering of dense graph, which includes
vertices is a, b, c, d. a high percentage of
possible edges, an adjacency
matrix is preferable.
Note: The adjacency matrix of a simple graph is symmetric, i.e., aij = aji
Also, since there are no loops, each diagonal entry aij for i = 1, 2, 3, …, n, is 0.
Adjacency Matrices (continued)
Adjacency matrices can also be used to represent graphs with loops and
multiple edges.
A loop at the vertex vi is represented by a 1 at the (i, j)th position of the
matrix.
When multiple edges connect the same pair of vertices vi and vj, (or if
multiple loops are present at the same vertex), the (i, j)th entry equals the
number of edges connecting the pair of vertices.
Example: We give the adjacency matrix of the pseudograph shown here
using the ordering of vertices a, b, c, d.
Adjacency Matrices (continued)
Adjacency matrices can also be used to represent directed
graphs. The matrix for a directed graph G = (V, E) has a 1 in its
(i, j)th position if there is an edge from vi to vj, where v1, v2, … vn
is a list of the vertices.
In other words, if the graphs adjacency matrix is AG = [aij], then
The adjacency matrix for a directed graph does not have to be symmetric,
because there may not be an edge from vi to vj, when there is an edge from vj
to vi.
To represent directed multigraphs, the value of aij is the number of edges
connecting vi to vj.
Representation of Graphs: Incidence
Matrices
Definition: Let G = (V, E) be an undirected graph
with vertices where v1, v2, … vn and edges
e1, e2, … em. The incidence matrix with respect to the
ordering of V and E is the n × m matrix M = [mij],
where
Incidence Matrices (continued)
Example: Simple Graph and Incidence Matrix
The rows going from top to
bottom represent v1 through
v5 and the columns going
from left to right represent e1
through e6.
However, G and H are not isomorphic. Note that since deg(a) = 2 in G, a must correspond
to t, u, x, or y in H, because these are the vertices of degree 2. But each of these vertices is
adjacent to another vertex of degree two in H, which is not true for a in G.
We define an injection f from the vertices of G to the vertices of H that preserves the degree of vertices.
We will determine whether it is an isomorphism.
The function f with f(u1) = v6, f(u2) = v3, f(u3) = v4, and f(u4) = v5 , f(u5) = v1, and f(u6) = v2 is a one-to-one
correspondence between G and H. Showing that this correspondence preserves edges is straightforward,
so we will omit the details here. Because f is an isomorphism, it follows that G and H are isomorphic
graphs.
See the text for an illustration of how adjacency matrices can be used for this verification.
Algorithms for Graph Isomorphism
The best algorithms known for determining whether two
graphs are isomorphic have exponential worst-case time
complexity (in the number of vertices of the graphs).
However, there are algorithms with linear average-case
time complexity.
You can use a public domain program called NAUTY to
determine in less than a second whether two graphs with
as many as 100 vertices are isomoprhic.
Graph isomorphism is a problem of special interest
because it is one of a few NP problems not known to be
either tractable or NP-complete (see Section 3.3).
Applications of Graph Isomorphism
The question whether graphs are isomorphic plays an important role in
applications of graph theory. For example,
chemists use molecular graphs to model chemical compounds. Vertices
represent atoms and edges represent chemical bonds. When a new
compound is synthesized, a database of molecular graphs is checked to
determine whether the graph representing the new compound is
isomorphic to the graph of a compound that this already known.
Electronic circuits are modeled as graphs in which the vertices represent
components and the edges represent connections between them. Graph
isomorphism is the basis for
the verification that a particular layout of a circuit corresponds to the
design’s original schematics.
determining whether a chip from one vendor includes the intellectual
property of another vendor.
Exercises
Connectivity
Section 10.4
Section Summary
Paths
Connectedness in Undirected Graphs
Vertex Connectivity and Edge Connectivity (not
currently included in overheads)
Connectedness in Directed Graphs
Paths and Isomorphism (not currently included in
overheads)
Counting Paths between Vertices
Paths
Informal Definition: A path is a sequence of edges that
begins at a vertex of a graph and travels from vertex to
vertex along edges of the graph. As the path travels along
its edges, it visits the vertices along this path, that is, the
endpoints of these.
Applications: Numerous problems can be modeled with
paths formed by traveling along edges of graphs such as:
determining whether a message can be sent between
two computers.
efficiently planning routes for mail delivery.
Paths
Definition: Let n be a nonnegative integer and G an undirected graph. A path of
length n from u to v in G is a sequence of n edges e1, … , en of G for which there exists a
sequence x0 = u, x1, …, xn-1, xn = v of vertices such that ei has, for i = 1, …, n, the
endpoints xi-1 and xi.
When the graph is simple, we denote this path by its vertex sequence x0,
x1, … , xn(since listing the vertices uniquely determines the path).
The path is a circuit if it begins and ends at the same vertex (u = v) and has length
greater than zero.
The path or circuit is said to pass through the vertices x1, x2, … , xn-1 and traverse
the edges e1, … , en.
A path or circuit is simple if it does not contain the same edge more than once.
Theorem: Let G be a graph with adjacency matrix A with respect to the ordering v1, … , vn
of vertices (with directed or undirected edges, multiple edges and loops allowed). The number of
different paths of length r from vi to vj, where r >0 is a positive integer, equals the (i,j)th entry of Ar.
Multigraph
Model of the
Bridges of
Kӧnigsberg
The 7 Bridges of Kӧnigsberg
Euler Paths and Circuits (continued)
Definition: An Euler circuit in a graph G is a simple circuit
containing every edge of G. An Euler path in G is a simple path
containing every edge of G.
Example: Which of the undirected graphs G1, G2, and G3 has a Euler
circuit? Of those that do not, which has an Euler path?
The path begins at a with an edge of the form {a, x}; we show that it must terminate at a
with an edge of the form {y, a}. Since each vertex has an even degree, there must be an
even number of edges incident with this vertex. Hence, every time we enter a vertex other
than a, we can leave it. Therefore, the path can only end at a.
If all
Inofthe
theexample
edges haveH consists of the
been used, an Euler circuit has been constructed. Otherwise,
vertices
consider thec,subgraph
d, e. H obtained from G by deleting the edges already used.
Sufficient Conditions for Euler Circuits
and Paths (continued)
Because G is connected, H must have at least one vertex in common with the circuit that has been deleted.
G1 contains exactly two vertices of odd degree (b and d). Hence it has an
Euler path, e.g., d, a, b, c, d, b.
G2 has exactly two vertices of odd degree (b and d). Hence it has an Euler
path, e.g., b, a, g, f, e, d, c, g, b, c, f, d.
G3 has six vertices of odd degree. Hence, it does not have an Euler path.
Applications of Euler Paths and Circuits
Euler paths and circuits can be used to solve many practical
problems such as finding a path or circuit that traverses each
street in a neighborhood,
road in a transportation network,
connection in a utility grid,
link in a communications network.
Other applications are found in the
layout of circuits,
network multicasting,
molecular biology, where Euler paths are used in the
sequencing of DNA.
William Rowan
Hamilton
(1805- 1865)
That is, a simple path x0, x1, …, xn-1, xn in the graph G = (V, E) is called a
Hamilton path if V = {x0, x1, … , xn-1, xn } and xi ≠ xj for 0≤ i < j ≤ n, and the
simple circuit x0, x1, …, xn-1, xn, x0 (with n > 0) is a Hamilton circuit if
x0, x1, … , xn-1, xn is a Hamilton path.
Hamilton Paths and Circuits (continued)
Example: Which of these simple graphs has a
Hamilton circuit or, if not, a Hamilton path?