BİM122 Lecture Note 8
BİM122 Lecture Note 8
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
Section
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.
Example:
a b
In this directed multigraph the
multiplicity of (a,b) is
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 .
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
Section
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
v , v , … , vn. The adjacency matrix AG of G, with
respect to the listing of vertices, is the n × n zero-one
matrix with as its (i, j)th entry when vi and vj are
adjacent, and 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 = , , , …, n, is .
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 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 in its (i, j)th position if there is an edge
from vi to vj, where v , v , … v is a list of the vertices.
In other words, if the graphs adjacency matrix is AG = [aij], then
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.
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.
Section
Section Summary
Paths
Connectedness in Undirected Graphs
Connectedness in Directed Graphs
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 = , …, 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 > is a positive
integer, equals the (i,j)th entry of Ar.
Multigraph
Model of the
Bridges of
K nigsberg
The 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?
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
( )
Solution: G a, b, c, d, e, a
G
a, b, c, d
G
Necessary Conditions for
Hamilton Circuits Gabriel Andrew Dirac
( )
Unlike for an Euler circuit, no simple necessary and sufficient
conditions are known for the existence of a Hamiton circuit.
However, there are some useful necessary conditions. We
describe two of these now.
Dirac’s Theorem: If G is a simple graph with n ≥ vertices such
that the degree of every vertex in G is ≥ n/ , then G has a
Hamilton circuit.