19 Graph Theory 1
19 Graph Theory 1
19 Graph Theory 1
Instructor:
MISHAL IQBAL
Topic
Graph & basic graph terminologies
Special Types of Graphs
Bipartite Graph
Application of Graph
Representing Graphs
Adjacency Lists
Adjacency & Incidence Matrices
Isomorphism of Graphs
3
Graphs Multigraph
A computer network may contain multiple links between data centers, as
shown in Figure.
To model such networks we need graphs that have more than one edge
connecting the same pair of vertices.
Graphs that may have multiple edges connecting the same vertices are
called multigraphs.
When there are m different edges associated to the same unordered pair
of vertices {u, v}, we also say that {u, v} is an edge of multiplicity m.
That is, we can think of this set of edges as m different copies of an edge
{u, v}.
8
Loops & Pseudo-
Graphs graphs
Sometimes a communications link connects a data center with itself,
perhaps a feedback loop for diagnostic purposes. Such a network is
illustrated in Figure.
To model this network we need to include edges that connect a vertex to
itself. Such edges are called loops, and sometimes we may even have
more than one loop at a vertex.
Graphs that may include loops, and possibly multiple edges connecting
the same pair of vertices or a vertex to itself, are sometimes called
pseudographs.
9
A directed graph may contain loops and it may contain multiple directed
edges that start and end at the same vertices.
When a directed graph has no loops and has no multiple directed edges,
it is called a simple directed graph.
Because a simple directed graph has at most one edge associated to
each ordered pair of vertices (u, v), we call (u, v) an edge if there is an
edge associated to it in the graph.
A directed graph may also contain directed edges that connect vertices u
and v in both directions; that is, when a digraph contains an edge from u
to v, it may also contain one or more edges from v to u.
12
Directed
Graphs Multigraphs
In some computer networks, multiple communication links between two
data centers may be present, as illustrated in Figure.
Directed graphs that may have multiple directed edges from a vertex to
a second (possibly the same) vertex are used to model such networks.
We called such graphs directed multigraphs. When there are m directed
edges, each associated to an ordered pair of vertices (u, v), we say that
(u, v) is an edge of multiplicity m.
13
Example: What are the degrees and what are the neighbourhoods of the
vertices in the graphs G and H displayed in Figure
Graphs 16
Terminology Theorem
Theorem 1: Let G = (V ,E) be an undirected graph with m edges. Then
Example: How many edges are there in a graph with 10 vertices each of
degree six?
Solution: Sum of the degrees of the vertices is 6 ・ 10 = 60, it follows
that 2m = 60 where m is the number of edges. Therefore, m = 30.
Theorem 1 shows that the sum of the degrees of the vertices of an
undirected graph is even.
Theorem 2: An undirected graph has an even number of vertices of odd
degree.
Graphs Basic Terminology
19
Because the edges in graphs with directed edges are ordered pairs, the
definition of the degree of a vertex can be refined to reflect the number
of edges with this vertex as the initial vertex and as the terminal vertex.
Graphs Basic Terminology
20
Graphs Cycles
Cycles: A cycle Cn, n ≥ 3, consists of n vertices v 1, v2, . . . , vn and edges
{v1, v2}, {v2, v3}, . . . , {vn−1, vn}, and {vn, v1}.
The cycles C3, C4, C5, and C6 are displayed in Figure.
Special Types of 24
Graphs Wheels
Wheels: We obtain a wheel Wn when we add an additional vertex to a
cycle Cn, for n ≥ 3, and connect this new vertex to each of the n vertices
in Cn, by new edges.
The wheels W3, W4, W5, and W6 are displayed in Figure.
Special Types of 25
Graphs n-Cubes
n-Cubes: An n-dimensional hypercube, or n-cube, denoted by Qn, is a
graph that has vertices representing the 2 n bit strings of length n.
Two vertices are adjacent if and only if the bit strings that they represent
differ in exactly one bit position. We display Q1, Q2, and Q3 in Figure.
Special Types of 26
Solution: Graph G is bipartite because its vertex set is the union of two
disjoint sets, {a, b, d} and {c, e, f, g}, and each edge connects a vertex
in one of these subsets to a vertex in the other subset.
(To be G bipartite it is not necessary that every vertex in {a, b, d} be
adjacent to every vertex in {c, e, f, g}. E.g., b and g are not adjacent.).
Graph H is not bipartite: its vertex set cannot be partitioned into two
subsets so that edges do not connect two vertices from the same subset.
Special Types of Complete Bipartite
28
Graphs Graphs
Complete Bipartite Graphs: A complete bipartite graph Km,n is a
graph that has its vertex set partitioned into two subsets of m and n
vertices, respectively with 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.
The complete bipartite graphs K2,3, K3,3, K3,5, and K2,6 are displayed in
Figure.
Special Types of 29
Graphs Applications
Bipartite graphs can be used to model many types of applications that
involve matching the elements of one set to elements of another.
Job Assignments
Marriages on an Island
Local Area Networks
The various computers in a building, such as minicomputers and
personal computers, as well as peripheral devices such as printers and
plotters, can be connected using a local area network.
Special Types of 30
Graphs Applications
Some of these networks are based on a star topology, where all devices
are connected to a central control device.
A local area network can be represented using a complete bipartite
graph K1,n, as shown in Figure (a).
Messages are sent from device to device through the central control
device.
Other local area networks are based on a ring topology, where each
device is connected to exactly two others. Local area networks with a
ring topology are modeled using n-cycles, Cn, as shown in Figure (b).
Messages are sent from device to device around the cycle until the
intended recipient of a message is reached.
Special Types of 31
Graphs Applications
Some local area networks use a hybrid of these two topologies.
Messages may be sent around the ring, or through a central device.
This redundancy makes the network more reliable.
Local area networks with this redundancy can be modeled using wheels
Wn, as shown in Figure (c).
Special Types of 32
Graphs Applications
Interconnection Networks for Parallel Computation
For many years, computers executed programs one operation at a time.
Consequently, the algorithms written to solve problems were designed
to perform one step at a time; such algorithms are called serial.
However, many computationally intense problems, such as weather
simulations, medical imaging, and cryptanalysis, cannot be solved in a
reasonable amount of time using serial operations, even on a
supercomputer. Parallel processing, which uses computers made up of
many separate processors, each with its own memory, helps overcome
the limitations of computers with a single processor. Parallel
algorithms, which break a problem into a number of subproblems that
can be solved concurrently.
Representing 33
Graphs Introduction
Graphs Graphs
Graphs Graphs
Graphs Matrices
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) is a simple graph where |V| = n. Suppose that
the vertices of G are listed arbitrarily as v1, v2, . . . , vn.
The adjacency matrix A (or AG) of G, with respect to this listing of the
vertices, is the n x 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 its adjacency matrix is A = [aij ], then
Representing Adjacency
37
Graphs Matrices
Graphs Matrices
Graphs Matrices
Note that an adjacency matrix of a graph is based on the ordering chosen
for the vertices.
Hence, there may be as many as n! different adjacency matrices for a
graph with n vertices, because there are n! different orderings of n
vertices.
The adjacency matrix of a simple graph is symmetric, that is, aij = aji ,
because both of these entries are 1 when vi and vj are adjacent, and both
are 0 otherwise.
Furthermore, because a simple graph has no loops, each entry aii, i = 1, 2,
3, . . . , n, is 0.
Representing Adjacency
40
Graphs Matrices
Adjacency matrices can also be used to represent undirected graphs with
loops and with multiple edges.
A loop at the vertex vi is represented by a 1 at the (i, i)th position of the
adjacency matrix.
When multiple edges connecting the same pair of vertices vi and vj, or
multiple loops at the same vertex, are present, the adjacency matrix is no
longer a zero–one matrix, because the (i, j )th entry of this matrix equals
the number of edges that are associated to {vi , vj }.
All undirected graphs, including multigraphs and pseudographs, have
symmetric adjacency matrices.
Representing Adjacency
41
Graphs Matrices
Graphs Matrices
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 an arbitrary listing
of the vertices of the directed graph.
In other words, if A = [aij ] is the adjacency matrix for the directed graph
with respect to this listing of the vertices, then
The adjacency matrix for a directed graph does not have to be symmetric,
because there may not be an edge from vj to vi when there is an edge from
vi to vj . In the adjacency matrix (not zero–one matrix) for a directed
multigraph, aij equals the number of edges that are associated to (vi , vj ).
Representing Incidence
43
Graphs Matrices
Graphs Matrices
Example: Represent the graph shown in Figure with an incidence
matrix.
Graphs Matrices
Incidence matrices can also be used to represent multiple edges and
loops. Multiple edges are represented in the incidence matrix using
columns with identical entries, because these edges are incident with the
same pair of vertices. Loops are represented using a column with exactly
one entry equal to 1, corresponding to the vertex that is incident with this
loop.
Example: Represent the
pseudograph shown in Figure
using an incidence matrix.
Solution: The incidence
matrix for this graph:
Isomorphism of 46
Graphs Introduction
Graphs Definition
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.
Isomorphism of simple graphs is an equivalence relation.
Isomorphism of 48
Graphs Example
Example: Show that the graphs G = (V ,E) and H = (W, F),
displayed in Figure, are isomorphic.
Solution: The function f with f (u1) = v1, f (u2) = v4, f
(u3) = v3, and f (u4) = v2 is a one-to-one correspondence
between V and W.
To see that this correspondence preserves adjacency, note
that adjacent vertices in G are u1 and u2, u1 and u3, u2 and u4,
and u3 and u4, and each of the pairs f (u1) = v1 and f
(u2) = v4, f (u1) = v1 and f (u3) = v3, f (u2) = v4 and f
(u4) = v2, and f (u3) = v3 and f (u4) = v2 consists of two
adjacent vertices in H.
Are Two Simple
Isomorphism of Graphs
49
Graphs Isomorphic?
Graphs Isomorphic?
For instance, isomorphic simple graphs must have the same number of
vertices, because there is a one-to-one correspondence between the sets
of vertices of the graphs.
Isomorphic simple graphs also must have the same number of edges,
because the one-to-one correspondence between vertices establishes a
one-to-one correspondence between edges.
In addition, the degrees of the vertices in isomorphic simple graphs must
be the same.
That is, a vertex v of degree d in G must correspond to a vertex f (v) of
degree d in H, because a vertex w in G is adjacent to v if and only if f (v)
and f (w) are adjacent in H.
Are Two Simple
Isomorphism of Graphs
51
Graphs Isomorphic?
Example: Show that the graphs
displayed in Figure are not isomorphic.
Solution: Both G and H have five
vertices and six edges.
However, H has a vertex of degree one,
namely, e, where as G has no vertices of
degree one.
It follows that G and H are not
isomorphic.
Are Two Simple
Isomorphism of Graphs
52
Graphs Isomorphic?
The number of vertices, the number of edges, and the number of vertices
of each degree 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.
Are Two Simple
Isomorphism of Graphs
53
Graphs Isomorphic?
Example: Determine whether the graphs shown in Figure are
isomorphic.
Solution: The graphs G and H both have eight vertices and 10
edges. They also both have four vertices of degree two and four of
degree three.
Because these invariants all agree, it is still conceivable that these
graphs are isomorphic.
However, G and H are not isomorphic. To see this, note that because
deg(a) = 2 in G, a must correspond to either t , u, x, or y in H,
because these are the vertices of degree two in H.
However, each of these four vertices in H is adjacent to another
vertex of degree two in H, which is not true for a in G.
54