Graphs
Graphs
Chapter 10
Graphs and Graph
Models
Section 10.1
Section Summary
• Introduction to Graphs
• Graph Taxonomy
• Graph Models
Chapter 10 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.
Basic Types of GRAPH
• Simple Graph
• Multi Graph
• Pseudo Graph
• Null Graph
• Complete Graph
• Regular Graph
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.
Remark:
• Graphs where the end points of an edge are not
ordered are said to be undirected graphs.
Some Terminology (continued)
Exampl
e:
multiplicity of (a,b) is 1 and the
In this directed multigraph the a b
multiplicity of (b,c) is 2.
c
Graph Terminology: Summary
• To understand the structure of a graph and to build a graph
model, we ask these questions:
• Are the edges of the graph undirected or directed (or both)?
• If the edges are undirected, are multiple edges present that connect the
same pair of vertices? If the edges are directed, are multiple directed
edges present?
• Are loops present?
Graph Terminology
and
Special Types of
Section 10.2
Graphs
Section Summary
• Basic Terminology
• Some Special Types of Graphs
• Bipartite Graphs
• Bipartite Graphs and Matchings
• Some Applications of Special Types of Graphs
• New Graphs from Old
Basic Terminology
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}.
Directed Graphs
• 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.
Special Types of Simple Graphs:
n-Cubes
subgraph of G if H ≠ G.
Example: Here we show K5 and one of its subgraphs.
• Adjacency Lists
• Adjacency Matrices
• Incidence Matrices
Representing Graphs:
Adjacency
Definition: Lists
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:
Representing Graphs: Adjacency Lists
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
zero-one matrix with 1 as its (i, j)th entry when vi and vj are adjacent,
matrix AG of G, with respect to the listing of vertices, is the n × n
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)
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)
The matrix for a directed graph G = (V, E) has a 1 in its (i, j)th
• Adjacency matrices can also be used to represent directed graphs.
• 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)
• Paths
• Connectedness in Undirected Graphs
• Connectedness in Directed Graphs
• Counting Paths between Vertices
Paths
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.
Paths (continued)
b, c, f, e, b is a circuit of length 4.
• d, e, c, a is not a path because e is not connected to c.
Solution: The graph G1 has an Euler circuit (e.g., a, e, c, d, e, b, a). But, as can
easily be verified by inspection, neither G2 nor G3 has an Euler circuit. Note that
G3 has an Euler path (e.g., a, c, d, e, b, d, a, b), but there is no Euler path in G2,
which can be verified by inspection.
Necessary Conditions for Euler Circuits
and Paths
• An Euler circuit begins with a vertex a and continues with an edge
incident with a, say {a, b}. The edge {a, b} contributes one to deg(a).
• Each time the circuit passes through a vertex it contributes two to the
vertex’s degree.
• Finally, the circuit terminates where it started, contributing one to
deg(a). Therefore deg(a) must be even.
• We conclude that the degree of every other vertex must also be even.
• By the same reasoning, we see that the initial vertex and the final
vertex of an Euler path have odd degree, while every other vertex has
even degree. So, a graph with an Euler path has exactly two vertices of
odd degree.
• In the next slide we will show that these necessary conditions are also
sufficient conditions.
Euler Circuits and Paths
Example:
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 Paths and Circuits
(1805- 1865)
Hamilton
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
Example: Which of these simple graphs has a Hamilton circuit or, if not, a
Hamilton path?
Solution:
G1 does not have a Hamilton circuit (Why?), but does have
a Hamilton path : a, b ,e , c, d.
G2 has a Hamilton circuit: a, b, c, d, e, a.
G3 has a Hamilton circuit: a,b,e,d,c,a
Necessary Conditions for
Hamilton Circuits Gabriel Andrew
Dirac
• Unlike for an Euler circuit, no simple necessary and sufficient
(1925-1984)
conditions are known for the existence of a Hamiton circuit.
• However, there are some useful necessary conditions. We describe
1968)
(1899-
Applications of Hamilton Paths and
Circuits
• Applications that ask for a path or a circuit that visits each
intersection of a city, each place pipelines intersect in a utility grid, or
each node in a communications network exactly once, can be solved
by finding a Hamilton path in the appropriate graph.
• The famous traveling salesperson problem (TSP) asks for the shortest
route a traveling salesperson should take to visit a set of cities. This
problem reduces to finding a Hamilton circuit such that the total sum
of the weights of its edges is as small as possible.
• A family of binary codes, known as Gray codes, which minimize the
effect of transmission errors, correspond to Hamilton circuits in the
n-cube Qn.
Shortest Paths
Weighted Graphs
CHI NY
SF DEN
ATL
LA
MIA
Weighted Graphs
MILES
BOS
2534 860
191
1855 722 NY
CHI
SF DEN 908
957
606
7 60
4
349 83
1090
2 45 1
ATL
LA 595
MIA
Weighted Graphs
FARES
BOS
$129 $79
$39
$99 $59 NY
CHI
SF DEN $ 69
$89
$ 79
$ 99
$39 $89 $129
ATL
LA
$ 69
MIA
Weighted Graphs
FLIGHT
TIMES
BOS
4:05
2:10
0:50
2:55 NY
CHI 1:50
SF DEN 2:10
2:20
1:55
1:4
2:45
0
1:15 2:00 3:50
ATL
LA
1:3
0
MIA
Weighted Graphs
• Each node is given a temporary label denoting the length of the shortest path
from the start node so far.
• Once it is certain that no other shorter paths can be found, the temporary
label becomes a permanent label.
• At this point the shortest path is found by retracing the path backwards.
Dijkstra’s algorithm: example
D(v) D(w) D(x) D(y) D(z)
Step N'
0 u 7,u 3,u 5,u ∞ ∞
1 uw 6,w 5,u 11,w ∞
2 uwx 6,w 11,w 14,x
3 uwxv 10,v 14,x
4 uwxvy 12,y
5 uwxvyz x
9
notes: 5
4
7
construct shortest path
8
tree by tracing
predecessor nodes u
3 w y z
ties can exist (can be 2
broken arbitrarily) 3
7 4
v
Dijkstra’s algorithm: another example
b 5 d 5 f
4 7
4 3 1
a 2 z
3 4
c 5 e 5 g