0% found this document useful (0 votes)
8 views

Mod3_Graph_Theory (1)

dnnnnnnnnnnnnnnnnnn dndhje

Uploaded by

PK Ki Vines
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Mod3_Graph_Theory (1)

dnnnnnnnnnnnnnnnnnn dndhje

Uploaded by

PK Ki Vines
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 169

ITT202:

Logic and Graph Theory


Module 3: Graph Theory
Instructor: Dr. Iqra Altaf Gillani
Introduction
● Graphs are discrete structures consisting of vertices and edges that connect
these vertices.
● There are different kinds of graphs, depending on whether edges have
directions, whether multiple edges can connect the same pair of vertices, and
whether loops are allowed.
Introduction
● Graphs are discrete structures consisting of vertices and edges that connect
these vertices.
● There are different kinds of graphs, depending on whether edges have
directions, whether multiple edges can connect the same pair of vertices, and
whether loops are allowed.
● Problems in almost every conceivable discipline can be solved using graph
models. For example: graphs are used to represent the competition of
different species in an ecological niche, graphs are used to represent who
influences whom in an organization, graphs are used to represent the
outcomes of round-robin tournaments.
Introduction
● Graphs are discrete structures consisting of vertices and edges that connect
these vertices.
● There are different kinds of graphs, depending on whether edges have
directions, whether multiple edges can connect the same pair of vertices, and
whether loops are allowed.
● Problems in almost every conceivable discipline can be solved using graph
models. For example: graphs are used to represent the competition of
different species in an ecological niche, graphs are used to represent who
influences whom in an organization, graphs are used to represent the
outcomes of round-robin tournaments.
● Other examples: model roadmaps, acquaintanceships between people,
collaboration between researchers, telephone calls between telephone
numbers, and links between websites.
What is a graph?
● A graph G = (V , E) consists of V , a nonempty set of vertices (or nodes) and
E, a set of edges.
● Each edge has either one or two vertices associated with it, called its
endpoints. An edge is said to connect its endpoints.
● The set of vertices V of a graph G may be infinite. A graph with an infinite
vertex set or an infinite number of edges is called an infinite graph, and in
comparison, a graph with a finite vertex set and a finite edge set is called a
finite graph. We will usually consider only finite graphs.
Example: Graphs
Suppose that a network is made up of data centers and communication links
between computers. We can represent the location of each data center by a point
and each communications link by a line segment, as shown in Figure 1.
Simple graph
● Note that each edge of the graph representing this computer network
connects two different vertices. That is, no edge connects a vertex to itself.
Furthermore, no two different edges connect the same pair of vertices.
● A graph in which each edge connects two different vertices and where no two
edges connect the same pair of vertices is called a simple graph.
● Note that in a simple graph, each edge is associated to an unordered pair of
vertices, and no other edge is associated to this same edge.
● When there is an edge of a simple graph associated to {u, v}, we can also
say, without possible confusion, that {u, v} is an edge of the graph.
Multigraph
● A computer network may contain multiple links between data centers, as
shown in Figure 2. 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}.
Pseudographs
● Sometimes a communications link connects a data center with itself, perhaps
a feedback loop for diagnostic purposes. Such a network is illustrated in
Figure 3.
● 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.
Undirected and Directed graphs
● So far the graphs we have introduced are undirected graphs. Their edges are
also said to be undirected.
● However, to construct a graph model, we may find it necessary to assign
directions to the edges of a graph. For example, in a computer network, some
links may operate in only one direction (such links are called single duplex
lines). This may be the case if there is a large amount of traffic sent to some
data centers, with little or no traffic going in the opposite direction. Such a
network is shown in Figure 4.
Directed graphs
● To model such a computer network we use a directed graph. Each edge of a
directed graph is associated to an ordered pair.
● A directed graph (or digraph) (V , E) consists of a nonempty set of vertices V
and a set of directed edges (or arcs) E. Each directed edge is associated with
an ordered pair of vertices. The directed edge associated with the ordered
pair (u, v) is said to start at u and end at v.
● When we depict a directed graph with a line drawing, we use an arrow
pointing from u to v to indicate the direction of an edge that starts at u and
ends at v.
● We obtain a directed graph when we assign a direction to each edge in an
undirected graph.
More versions of Directed graphs
● 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.
● 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 as 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.
Mixed graphs
● For some models we may need a graph where some edges are undirected,
while others are directed. A graph with both directed and undirected edges is
called a mixed graph.
● For example, a mixed graph might be used to model a computer network
containing links that operate in both directions and other links that operate
only in one direction.
Graph terminology revisited
Graph terminology revisited
Popular Graph Models: Social Networks
● Graphs are extensively used to model social structures based on different
kinds of relationships between people or groups of people.
● These social structures, and the graphs that represent them, are known as
social networks. In these graph models, individuals or organizations are
represented by vertices; relationships between individuals or organizations
are represented by edges.
● The study of social networks is an extremely active multidisciplinary area, and
many different types of relationships between people have been studied using
them.
Popular Graph Models: Acquaintanceship and
Friendship Graphs
● We can use a simple graph to represent
whether two people know each other, that
is, whether they are acquainted, or whether
they are friends (either in the real world in
the virtual world via a social networking site
such as Facebook).
● Each person in a particular group of people
is represented by a vertex. An undirected
edge is used to connect two people when
these people know each other, when we
are concerned only with acquaintanceship,
or whether they are friends.
Popular Graph Models: Communication Networks
We can model different communications networks using vertices to represent
devices and edges to represent the particular type of communications links of
interest. For example: Call Graphs.
Popular Graph Models: Communication Networks
We can model different communications networks using vertices to represent
devices and edges to represent the particular type of communications links of
interest. For example: Call Graphs.

● Graphs can be used to model telephone calls made in a network, such as a


long-distance telephone network. In particular, a directed multigraph can be
used to model calls where each telephone number is represented by a vertex
and each telephone call is represented by a directed edge.
● The edge representing a call starts at the telephone number from which the
call was made and ends at the telephone number to which the call was made.
● We need directed edges because the direction in which the call is made
matters.
● We need multiple directed edges because we want to represent each call
made from a particular telephone number to a second number.
Popular Graph Models: Information Networks
Graphs can be used to model various networks that link particular types of
information. For example: Web graph, citation graphs.

● Graphs can be used to represent citations in different types of documents,


including academic papers, patents, and legal opinions. In such graphs, each
document is represented by a vertex, and there is an edge from one
document to a second document if the first document cites the second in its
citation list.
● A citation graph is a directed graph without loops or multiple edges.
Popular Graph Models: Software Design Applications
Graph models are useful tools in the design of software. For example: precedence
graphs and module dependency graphs.

● Module Dependency Graphs: One of the most important tasks in designing


software is how to structure a program into different parts, or modules.
● Understanding how the different modules of a program interact is essential
not only for program design, but also for testing and maintenance of the
resulting software.
● A module dependency graph provides a useful tool for understanding how
different modules of a program interact.
● In a program dependency graph, each module is represented by a vertex.
There is a directed edge from a module to a second module if the second
module depends on the first.
Popular Graph Models: Software Design Applications
Graph models are useful tools in the design of software. For example: precedence
graphs and module dependency graphs.
Popular Graph Models: Transportation Networks
We can use graphs to model many different types of transportation networks,
including road, air, and rail networks, as well shipping networks.

● Airline Routes: We can model airline networks by representing each airport


by a vertex. In particular, we can model all the flights by a particular airline
each day using a directed edge to represent each flight, going from the vertex
representing the departure airport to the vertex representing the destination
airport.
● The resulting graph will generally be a directed multigraph, as there may be
multiple flights from one airport to some other airport during the same day.
Popular Graph Models: Biological Networks
Many aspects of the biological sciences can be modeled using graphs.

● Protein Interaction Graphs: A protein interaction in a living cell occurs when


two or more proteins in that cell bind to perform a biological function. Because
protein interactions are crucial for most biological functions, many scientists
work on discovering new proteins and understanding interactions between
proteins.
● Protein interactions within a cell can be modeled using a protein interaction
graph (also called a protein–protein interaction network), an undirected graph
in which each protein is represented by a vertex, with an edge connecting the
vertices representing each pair of proteins that interact.
Popular Graph Models: Round-Robin Tournament
● A tournament where each team plays every other team
exactly once and no ties are allowed is called a
round-robin tournament.
● Such tournaments can be modeled using directed
graphs where each team is represented by a vertex.
Note that (a, b) is an edge if team a beats team b.
● This graph is a simple directed graph, containing no
loops or multiple directed edges (because no two
teams play each other more than once).
Basic Terminologies
● Two vertices u and v in an undirected graph G are called adjacent (or
neighbors) in G if u and v are endpoints of an edge e of G. Such an edge e is
called incident with the vertices u and v and e is said to connect u and v.
Basic Terminologies
● Two vertices u and v in an undirected graph G are called adjacent (or
neighbors) in G if u and v are endpoints of an edge e of G. Such an edge e is
called incident with the vertices u and v and e is said to connect u and v.
● The set of all neighbors of a vertex v of G = (V , E), denoted by N(v), is called
the neighborhood of v. If A is a subset of V, we denote by N(A) the set of all
vertices in G that are adjacent to at least one vertex in A. So, N (A) = ∪ _v∈A
N(v).
Basic Terminologies
● Two vertices u and v in an undirected graph G are called adjacent (or
neighbors) in G if u and v are endpoints of an edge e of G. Such an edge e is
called incident with the vertices u and v and e is said to connect u and v.
● The set of all neighbors of a vertex v of G = (V , E), denoted by N(v), is called
the neighborhood of v. If A is a subset of V, we denote by N(A) the set of all
vertices in G that are adjacent to at least one vertex in A. So, N (A) = ∪ _v∈A
N(v).
● 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 v is denoted by deg(v).
Basic Terminologies
● 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 v is denoted by deg(v).
● A vertex of degree zero is called isolated. It follows that an isolated vertex
is not adjacent to any vertex.
● A vertex is pendant if and only if it has degree one. Consequently, a
pendant vertex is adjacent to exactly one other vertex.
Handshaking Theorem
Handshaking Theorem

Example: How many edges are there in a graph with 10 vertices each of degree
six?
Handshaking Theorem

Example: How many edges are there in a graph with 10 vertices each of degree
six?

Solution: Because the 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.
Consequent result
Basic Terminologies: Directed Graphs
● When (u, v) is an edge of the graph G with directed edges, u is said to be
adjacent to v and v is said to be adjacent from u. The vertex u is called the
initial vertex of (u, v), and v is called the terminal or end vertex of (u, v).
The initial vertex and terminal vertex of a loop are the same.
● In a graph with directed edges the in-degree of a vertex v, denoted by deg −
(v), is the number of edges with v as their terminal vertex. The out-degree of
v, denoted by deg + (v), is the number of edges with v 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.
Basic Terminologies: Directed Graphs
● When (u, v) is an edge of the graph G with directed edges, u is said to be
adjacent to v and v is said to be adjacent from u. The vertex u is called the
initial vertex of (u, v), and v is called the terminal or end vertex of (u, v).
The initial vertex and terminal vertex of a loop are the same.
● In a graph with directed edges the in-degree of a vertex v, denoted by deg −
(v), is the number of edges with v as their terminal vertex. The out-degree of
v, denoted by deg + (v), is the number of edges with v 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.
● Theorem:
Basic Terminologies: Directed Graphs
Basic Terminologies: Directed Graphs
Special Simple Graphs
● A complete graph on n vertices, denoted by K_n , is a simple graph that
contains exactly one edge between each pair of distinct vertices. The graphs
K n , for n = 1, 2, 3, 4, 5, 6, are displayed in Figure. A simple graph for which
there is at least one pair of distinct vertex not connected by an edge is called
non-complete.
Special Simple Graphs
● A cycle C_n , n ≥ 3, consists of n vertices v 1 , v 2 , . . . , v n and edges {v 1 , v
2 }, {v 2 , v 3 }, . . . , {v n−1 , v n }, and {v n , v 1 }. The cycles C 3 , C 4 , C 5 ,
and C 6 are displayed in Figure.
Special Simple Graphs
● A cycle C_n , n ≥ 3, consists of n vertices v 1 , v 2 , . . . , v n and edges {v 1 , v
2 }, {v 2 , v 3 }, . . . , {v n−1 , v n }, and {v n , v 1 }. The cycles C 3 , C 4 , C 5 ,
and C 6 are displayed in Figure.

● A wheel W_n when we add an additional vertex to a cycle C n , for n ≥ 3, and


connect this new vertex to each of the n vertices in C n , by new edges. The
wheels W 3 , W 4 , W 5 , and W 6 are displayed in Figure.
Special Simple Graphs
● An n-dimensional hypercube, or n-cube, denoted by Q_n , 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.
Some Applications of Special Types of Graphs
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.
Some Applications of Special Types of Graphs
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 intensive 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.
Some Applications of Special Types of Graphs
Interconnection Networks for Parallel Computation.
Bipartite Graph
● A simple graph G is called bipartite if its vertex set V can be partitioned into
two disjoint sets V 1 and V 2 such that every edge in the graph connects a
vertex in V 1 and a vertex in V 2 (so that no edge in G connects either two
vertices in V 1 or two vertices in V 2 ).
● When this condition holds, we call the pair (V 1 , V 2 ) a bipartition of the
vertex set V of G.
Example: Bipartite graph
Are G and H bipartite graphs?
Example: Bipartite graph
Are G and H bipartite graphs?

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. Graph H is not bipartite because its vertex set cannot
be partitioned into two subsets so that edges do not connect two vertices from the
same subset.
Bipartite graph property
Bipartite graph property
Complete Bipartite Graphs
● A complete bipartite graph K m,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 K 2,3 , K 3,3 , K 3,5 , and K 2,6 are displayed
in Figure.
Bipartite Graphs and Matchings
● A matching M in a simple graph G = (V , E) is a subset of the set E of edges
of the graph such that no two edges are incident with the same vertex.
● In other words, a matching is a subset of edges such that if {s, t} and {u, v}
are distinct edges of the matching, then s, t, u, and v are distinct.
● A maximum matching is a matching of maximum size (maximum number of
edges).
● Suppose that there are m employees in a group and n different jobs that need
to be done, where m ≥ n. Each employee is trained to do one or more of
these n jobs. We would like to assign an employee to each job.
Bipartite Graphs and Matchings
● Suppose that there are m employees in a group and n different jobs that need
to be done, where m ≥ n. Each employee is trained to do one or more of
these n jobs. We would like to assign an employee to each job.
New Graphs from Old
● A subgraph of a graph G = (V , E) is a graph H = (W, F ), where W ⊆ V and F
⊆ E. A subgraph H of G is a proper subgraph of G if H ≠ G.
● 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 of this edge are in W .
New Graphs from Old
● A subgraph of a graph G = (V , E) is a graph H = (W, F ), where W ⊆ V and F
⊆ E. A subgraph H of G is a proper subgraph of G if H ≠ G.
● 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 of this edge are in W .
● Example: The graph G shown in Figure is a subgraph of K_5 .
New Graphs from Old
● A subgraph of a graph G = (V , E) is a graph H = (W, F ), where W ⊆ V and F
⊆ E. A subgraph H of G is a proper subgraph of G if H ≠ G.
● 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 of this edge are in W .
● Example: The graph G shown in Figure is a subgraph of K_5 . If we add the
edge connecting c and e to G, we obtain the subgraph induced by W = {a, b,
c, e}.
Removing or adding edges of a graph
● Given a graph G = (V , E) and an edge e ∈ E, we can produce a subgraph of
G by removing the edge e. The resulting subgraph, denoted by G − e, has the
same vertex set V as G. Its edge set is E − e. Hence, G − e = (V , E − {e}).
● Similarly, if E’ is a subset of E, we can produce a subgraph of G by removing
the edges in E’ from the graph. The resulting subgraph has the same vertex
set V as G. Its edge set is E − E’ .
● We can also add an edge e to a graph to produce a new larger graph when
this edge connects two vertices already in G. We denote by G + e the new
graph produced by adding a new edge e, connecting two previously
nonincident vertices, to the graph G. Hence, G + e = (V , E ∪ {e}).
● The vertex set of G + e is the same as the vertex set of G and the edge set is
the union of the edge set of G and the set {e}.
Edge contractions
● Sometimes when we remove an edge from a graph, we do not want to retain
the endpoints of this edge as separate vertices in the resulting subgraph.
● In such a case we perform an edge contraction which removes an edge e with
endpoints u and v and merges u and w into a new single vertex w, and for
each edge with u or v as an endpoint replaces the edge with one with w as
endpoint in place of u or v and with the same second endpoint.
● Hence, the contraction of the edge e with endpoints u and v in the graph G =
(V , E) produces a new graph G = (V , E ) (which is not a subgraph of G),
where V = V − {u, v} ∪ {w} and E contains the edges in E which do not have
either u or v as endpoints and an edge connecting w to every neighbor of
either u or v in V .
Some more operations
● When we remove a vertex v and all edges incident to it from G = (V , E), we
produce a subgraph, denoted by G − v. Observe that G − v = (V − v, E’),
where E’ is the set of edges of G not incident to v.
● Similarly, if V’ is a subset of V , then the graph G − V’ is the subgraph (V − V’,
E’), where E’ is the set of edges of G not incident to a vertex in V’ .
● The union of two simple graphs G 1 = (V 1 , E 1 ) and G 2 = (V 2 , E 2 ) is the
simple graph with vertex set V 1 ∪ V 2 and edge set E 1 ∪ E 2 . The union of
G 1 and G 2 is denoted by G 1 ∪ G 2 .
Graph Representation
1. Edge list: List all edges in graph.

2. Adjacency lists: which specify the vertices that are adjacent to each vertex of
the graph.
Graph Representation
1. Edge list: List all edges in graph.

2. Adjacency lists: which specify the vertices that are adjacent to each vertex of
the graph.
Graph Representation
1. Adjacency Matrix: Suppose that G = (V , E) is a simple graph where |V | = n.
Suppose that the vertices of G are listed arbitrarily as v 1 , v 2 , . . . , v n . The
adjacency matrix A (or A G ) 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 v i and v j are adjacent, and 0
as its (i, j )th entry when they are not adjacent. In other words, if its adjacency
matrix is A = [a ij ], then
Graph Representation
1. Adjacency Matrix: Suppose that G = (V , E) is a simple graph where |V | = n.
Suppose that the vertices of G are listed arbitrarily as v 1 , v 2 , . . . , v n . The
adjacency matrix A (or A G ) 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 v i and v j are adjacent, and 0
as its (i, j )th entry when they are not adjacent. In other words, if its adjacency
matrix is A = [a ij ], then
Graph Representation
1. Adjacency Matrix: Suppose that G = (V , E) is a simple graph where |V | = n.
Suppose that the vertices of G are listed arbitrarily as v 1 , v 2 , . . . , v n . The
adjacency matrix A (or A G ) 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 v i and v j are adjacent, and 0
as its (i, j )th entry when they are not adjacent. In other words, if its adjacency
matrix is A = [a ij ], then
Graph Representation
1. Adjacency Matrix: Suppose that G = (V , E) is a simple graph where |V | = n.
Suppose that the vertices of G are listed arbitrarily as v 1 , v 2 , . . . , v n . The
adjacency matrix A (or A G ) 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 v i and v j are adjacent, and 0
as its (i, j )th entry when they are not adjacent. In other words, if its adjacency
matrix is A = [a ij ], then
Graph Representation
1. Adjacency Matrix: Suppose that G = (V , E) is a simple graph where |V | = n.
Suppose that the vertices of G are listed arbitrarily as v 1 , v 2 , . . . , v n . The
adjacency matrix A (or A G ) 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 v i and v j are adjacent, and 0
as its (i, j )th entry when they are not adjacent. In other words, if its adjacency
matrix is A = [a ij ], then
Graph Representation: More about adjacency matrix
● The adjacency matrix of a simple graph is symmetric, that is, a ij = a j i , because
both of these entries are 1 when v i and v j are adjacent, and both are 0 otherwise.
Furthermore, as a simple graph has no loops, each entry a ii , i = 1, 2, . . , n, is 0.
● Adjacency matrices can also be used to represent undirected graphs with loops
and with multiple edges.
● A loop at the vertex v i is represented by a 1 at the (i, i)th position of the adjacency
matrix.
● When multiple edges connecting the same pair of vertices v i and v j , 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 {v i , v j }.
● All undirected graphs, including multigraphs and pseudographs, have symmetric
adjacency matrices.
Graph Representation
Q) Use an adjacency matrix to represent the pseudograph shown in Figure.
Graph Representation
Q) Use an adjacency matrix to represent the pseudograph shown in Figure.
Graph Representation: Adjacency matrix for 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 v i to v j , where v 1 , v 2 , . . . , v n is an arbitrary listing
of the vertices of the directed graph.
● In other words, if A = [a ij ] is the adjacency matrix for the directed graph with
respect to this listing of the vertices, then
Graph Representation: Adjacency matrix for 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 v i to v j , where v 1 , v 2 , . . . , v n is an arbitrary listing
of the vertices of the directed graph.
● In other words, if A = [a ij ] is the adjacency matrix for the directed graph with
respect to this listing of the vertices, then
Graph Representation: Adjacency matrix for 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 v i to v j , where v 1 , v 2 , . . . , v n is an arbitrary listing
of the vertices of the directed graph.
● In other words, if A = [a ij ] 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 v j to v i when there is an edge from
v i to v j .
● In the adjacency matrix for a directed multigraph, a ij equals the number of
edges that are associated to (v i , v j ).
Adjacency list versus Adjacency matrix: Sparse case
Adjacency list versus Adjacency matrix: Sparse case
● When a simple graph contains relatively few edges, that is, when it is sparse,
it is usually preferable to use adjacency lists rather than an adjacency matrix
to represent the graph. For example, if each vertex has degree not exceeding
c, where c is a constant much smaller than n, then each adjacency list
contains c or fewer vertices. Hence, there are no more than cn items in all
these adjacency lists. On the other hand, the adjacency matrix for the graph
has n^2 entries.
● Note, however, that the adjacency matrix of a sparse graph is a sparse matrix,
that is, a matrix with few nonzero entries, and there are special techniques for
representing, and computing with, sparse matrices.
Adjacency list versus Adjacency matrix: Dense case
Adjacency list versus Adjacency matrix: Dense case
● For a dense graph, that is, suppose that it contains many edges, such as a
graph that contains more than half of all possible edges. In this case, using an
adjacency matrix to represent the graph is usually preferable over using
adjacency lists.
● To see why, we compare the complexity of determining whether the possible
edge {v i , v j } is present. Using an adjacency matrix, we can determine
whether this edge is present by examining the (i, j )th entry in the matrix. This
entry is 1 if the graph contains this edge and is 0 otherwise. Consequently, we
need make only one comparison, to determine whether this edge is present.
● On the other hand, when we use adjacency lists to represent the graph, we
need to search the list of vertices adjacent to either v i or v j to determine
whether this edge is present. This can require (|V |) comparisons when many
edges are present.
Graph Representation: Incidence matrix
Another common way to represent graphs is to use incidence matrices. Let G =
(V , E) be an undirected graph. Suppose that v 1 , v 2 , . . . , v n are the vertices
and e 1 , e 2 , . . . , e m are the edges of G. Then the incidence matrix with
respect to this ordering of V and E is the n × m matrix M = [m ij ], where
Graph Representation: Incidence matrix
Another common way to represent graphs is to use incidence matrices. Let G =
(V , E) be an undirected graph. Suppose that v 1 , v 2 , . . . , v n are the vertices
and e 1 , e 2 , . . . , e m are the edges of G. Then the incidence matrix with
respect to this ordering of V and E is the n × m matrix M = [m ij ], where

Examples:
Graph Representation: Incidence matrix
Another common way to represent graphs is to use incidence matrices. Let G =
(V , E) be an undirected graph. Suppose that v 1 , v 2 , . . . , v n are the vertices
and e 1 , e 2 , . . . , e m are the edges of G. Then the incidence matrix with
respect to this ordering of V and E is the n × m matrix M = [m ij ], where

Examples:
Graph Representation: Incidence matrix
Another common way to represent graphs is to use incidence matrices. Let G =
(V , E) be an undirected graph. Suppose that v 1 , v 2 , . . . , v n are the vertices
and e 1 , e 2 , . . . , e m are the edges of G. Then the incidence matrix with
respect to this ordering of V and E is the n × m matrix M = [m ij ], where

Examples:
Isomorphism of Graphs
● The simple graphs G 1 = (V 1 , E 1 ) and G 2 = (V 2 , E 2 ) are isomorphic if
there exists a one-to-one and onto function f from V 1 to V 2 with the property
that a and b are adjacent in G 1 if and only if f (a) and f (b) are adjacent in G 2,
for all a and b in V 1 . Such a function f is called an isomorphism.
● Two simple graphs that are not isomorphic are called nonisomorphic.
● 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.
Example: Isomorphism of Graphs
Show that the graphs G = (V , E) and H = (W, F ),
displayed in Figure are isomorphic.

Soln:
Example: Isomorphism of Graphs
Show that the graphs G = (V , E) and H = (W, F ), displayed
in Figure are isomorphic.

Soln: The function f with f (u 1 ) = v 1 , f (u 2 ) = v 4 , f (u 3 ) =


v 3 , and f (u 4 ) = v 2 is a one-to-one correspondence
between V and W . To see that this correspondence
preserves adjacency, note that adjacent vertices in G are u 1
and u 2 , u 1 and u 3 , u 2 and u 4 , and u 3 and u 4 , and
each of the pairs f (u 1 ) = v 1 and f (u 2 ) = v 4 , f (u 1 ) = v 1
and f (u 3 ) = v 3 , f (u 2 ) = v 4 and f (u 4 ) = v 2 , and f (u 3 )
= v 3 and f (u 4 ) = v 2 consists of two adjacent vertices in H .
Determining whether Two Simple Graphs are
Isomorphic
● It is often difficult to determine whether two simple graphs are isomorphic.
There are n! Possible one-to-one correspondences between the vertex sets of
two simple graphs with n vertices. Testing each such correspondence to see
whether it preserves adjacency and nonadjacency is impractical if n is at all
large.
● Sometimes it is not hard to show that two graphs are not isomorphic. In
particular, we can show that two graphs are not isomorphic if we can find a
property only one of the two graphs has, but that is preserved by
isomorphism.
● A property preserved by isomorphism of graphs is called a graph invariant.
Graph Invariant
● 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 .
Graph Invariant
● 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.
Examples: Isomorphism
Check whether the graphs in given figure are isomorphic to each other or not.
Examples: Isomorphism
Check whether the graphs in given figure are isomorphic to each other or not.

Soln: Both G and H have five vertices and six edges. However, H has a vertex of
degree one, namely, e, whereas G has no vertices of degree one. It follows that G
and H are not isomorphic.
Isomorphism using Adjacency matrix
● To show that a function f from the vertex set of a graph G to the vertex set of a
graph H is an isomorphism, we need to show that f preserves the presence
and absence of edges.
● One helpful way to do this is to use adjacency matrices. In particular, to show
that f is an isomorphism, we can show that the adjacency matrix of G is the
same as the adjacency matrix of H , when rows and columns are labeled to
correspond to the images under f of the vertices in G that are the labels of
these rows and columns in the adjacency matrix of G.
Example: Isomorphism using Adjacency matrix
Determine whether the graphs G and H displayed in Figure are isomorphic.

Solution: Both G and H have six vertices and seven edges. Both have four
vertices of degree two and two vertices of degree three. It is also easy to see that
the subgraphs of G and H consisting of all vertices of degree two and the edges
connecting them are isomorphic (as the reader should verify). Because G and H
agree with respect to these invariants, it is reasonable to try to find an
isomorphism f .
Example: Isomorphism using Adjacency matrix
We now will define a function f and then determine whether it is an isomorphism.
Because deg(u 1 ) = 2 and because u 1 is not adjacent to any other vertex of
degree two, the image of u 1 must be either v 4 or v 6 , the only vertices of degree
two in H not adjacent to a vertex of degree two. We arbitrarily set f (u 1 ) = v 6 .
Because u 2 is adjacent to u 1 , the possible images of u 2 are v 3

and v 5 . We arbitrarily set

f (u 2 ) = v 3 . Continuing in this way,

using adjacency of vertices and

degrees as a guide, we set f (u 3 ) = v 4 , f (u 4 ) = v 5 , f (u 5 ) = v 1 , and f (u 6 ) =


v2.
Example: Isomorphism using Adjacency matrix

Because A G = A H , it follows that f


preserves edges. We conclude that f is an
isomorphism, so G and H are isomorphic.
Applications of Graph Isomorphism
● Graph isomorphisms, and functions that are almost graph isomorphisms,
arise in applications of graph theory to chemistry and to the design of
electronic circuits, and other areas including bioinformatics and computer
vision.
Applications of Graph Isomorphism
● Graph isomorphisms, and functions that are almost graph isomorphisms,
arise in applications of graph theory to chemistry and to the design of
electronic circuits, and other areas including bioinformatics and computer
vision.
● Chemistry: Chemists use multigraphs, known as molecular graphs, to model
chemical compounds. In these graphs, vertices represent atoms and edges
represent chemical bonds between these atoms.
● Two structural isomers, molecules with identical molecular formulas but with
atoms bonded differently, have nonisomorphic molecular graphs. When a
potentially new chemical compound is synthesized, a database of molecular
graphs is checked to see whether the molecular graph of the compound is the
same as one already known.
Applications of Graph Isomorphism
● Chip-design: Electronic circuits are modeled using graphs in which vertices
represent components and edges represent connections between them.
Modern integrated circuits, known as chips, are miniaturized electronic
circuits, often with millions of transistors and connections between them.
Because of the complexity of modern chips, automation tools are used to
design them.
● Graph isomorphism is the basis for the verification that a particular layout of a
circuit produced by an automated tool corresponds to the original schematic
of the design. Graph isomorphism can also be used to determine whether a
chip from one vendor includes intellectual property from a different vendor.
This can be done by looking for large isomorphic subgraphs in the graphs
modeling these chips.
Connectivity
● Many problems can be modeled with 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.
● Problems of efficiently planning routes for mail delivery, garbage pickup,
diagnostics in computer networks, and so on can be solved using models that
involve paths in graphs.
Paths
● Informally, 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 edges.
● 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 e 1 , . . . , e n of G for which there
exists a sequence x 0 = u, x 1 , . . . , x n−1 , x n = v of vertices such that e i
has, for i = 1, . . . , n, the endpoints x i−1 and x i .
● When the graph is simple, we denote this path by its vertex sequence x 0 , x 1
, . . . , x n (because listing these vertices uniquely determines the path).
Paths, circuits
● The path is a circuit if it begins and ends at the same vertex, that is, if u = v,
and has length greater than zero.
● The path or circuit is said to pass through the vertices x 1 , x 2 , . . . , x n−1 or
traverse the edges e 1 , e 2 , . . . , e n . A path or circuit is simple if it does not
contain the same edge more than once.
Paths, circuits
● The path is a circuit if it begins and ends at the same vertex, that is, if u = v,
and has length greater than zero.
● The path or circuit is said to pass through the vertices x 1 , x 2 , . . . , x n−1 or
traverse the edges e 1 , e 2 , . . . , e n . A path or circuit is simple if it does not
contain the same edge more than once.
● The term walk is used instead of path, where a walk is defined to be an
alternating sequence of vertices and edges of a graph, v 0 , e 1 , v 1 , e 2 , . . . ,
v n−1 , e n , v n , where v i−1 and v i are the endpoints of e i for i = 1, 2, . . . , n.
Paths, circuits
● The path is a circuit if it begins and ends at the same vertex, that is, if u = v,
and has length greater than zero.
● The path or circuit is said to pass through the vertices x 1 , x 2 , . . . , x n−1 or
traverse the edges e 1 , e 2 , . . . , e n . A path or circuit is simple if it does not
contain the same edge more than once.
● The term walk is used instead of path, where a walk is defined to be an
alternating sequence of vertices and edges of a graph, v 0 , e 1 , v 1 , e 2 , . . . ,
v n−1 , e n , v n , where v i−1 and v i are the endpoints of e i for i = 1, 2, . . . , n.
● When this terminology is used, closed walk is used instead of circuit to indicate
a walk that begins and ends at the same vertex, and trail is used to denote a
walk that has no repeated edge (replacing the term simple path).
● When this terminology is used, the terminology path is often used for a trail with
no repeated vertices.
Example: Paths
● In the simple graph shown in Figure 1, a, d, c, f , e a simple path?
Example: Paths
● In the simple graph shown in Figure 1, a, d, c, f , e a simple path? Yes, of
length 4, because {a, d}, {d, c}, {c, f }, and {f, e} are all edges.
● What about d, e, c, a?
Example: Paths
● In the simple graph shown in Figure 1, a, d, c, f , e a simple path? Yes, of
length 4, because {a, d}, {d, c}, {c, f }, and {f, e} are all edges.
● What about d, e, c, a? No, it is not a path, because {e, c} is not an edge.
● Identify any circuit.
Example: Paths
● In the simple graph shown in Figure 1, a, d, c, f , e a simple path? Yes, of
length 4, because {a, d}, {d, c}, {c, f }, and {f, e} are all edges.
● What about d, e, c, a? No, it is not a path, because {e, c} is not an edge.
● Identify any circuit. b, c, f , e, b is a circuit of length 4 because {b, c}, {c, f }, {f,
e}, and {e, b} are edges, and this path begins and ends at b.
● Is path a, b, e, d, a, b, a simple one?
Example: Paths
● In the simple graph shown in Figure 1, a, d, c, f , e a simple path? Yes, of
length 4, because {a, d}, {d, c}, {c, f }, and {f, e} are all edges.
● What about d, e, c, a? No, it is not a path, because {e, c} is not an edge.
● Identify any circuit. b, c, f , e, b is a circuit of length 4 because {b, c}, {c, f }, {f,
e}, and {e, b} are edges, and this path begins and ends at b.
● Is path a, b, e, d, a, b, a simple one? No, it is not simple because it contains
the edge {a, b} twice.
Paths: Directed scenario
● Let n be a nonnegative integer and G a directed graph. A path of length n
from u to v in G is a sequence of edges e 1 , e 2 , . . . , e n of G such that e 1
is associated with (x 0 , x 1 ), e 2 is associated with (x 1 , x 2 ), and so on,
with e n associated with (x n−1 , x n ), where x 0 = u and x n = v.
● When there are no multiple edges in the directed graph, this path is denoted
by its vertex sequence x 0 , x 1 , x 2 , . . . , x n .
● A path of length greater than zero that begins and ends at the same vertex is
called a circuit or cycle.
● A path or circuit is called simple if it does not contain the same edge more
than once.
Path applications
● Paths in Acquaintanceship Graphs: In an acquaintanceship graph there is
a path between two people if there is a chain of people linking these people,
where two people adjacent in the chain know one another.
● Many social scientists have conjectured that almost every pair of people in the
world are linked by a small chain of people, perhaps containing just five or
fewer people. This would mean that almost every pair of vertices in the
acquaintanceship graph containing all people in the world is linked by a path
of length not exceeding four.
Path applications
● Paths in Collaboration Graphs: In a collaboration graph, two people a and b
are connected by a path when there is a sequence of people starting with a
and ending with b such that the endpoints of each edge in the path are people
who have collaborated.
● We will consider the academic collaboration graph of people who have written
papers in mathematics, the Erdős number of a person m is the length of the
shortest path between m and the extremely prolific mathematician Paul Erdős
(who died in 1996).
Connectedness in Undirected Graphs
● When a graph is used to represent this computer network, where vertices
represent the computers and edges represent the communication links, this
question becomes: When is there always a path between two vertices in the
graph?
Connectedness in Undirected Graphs
● When a graph is used to represent this computer network, where vertices
represent the computers and edges represent the communication links, this
question becomes: When is there always a path between two vertices in the
graph?
● An undirected graph is called connected if there is a path between every pair
of distinct vertices of the graph. An undirected graph that is not connected is
called disconnected. We say that we disconnect a graph when we remove
vertices or edges, or both, to produce a disconnected subgraph.
● There is a simple path between every pair of distinct vertices of a connected
undirected graph.
Example: Connected graphs
Connected Component
● A connected component of a graph G is a connected sub-graph of G that is
not a proper subgraph of another connected subgraph of G.
● That is, a connected component of a graph G is a maximal connected
subgraph of G.
● A graph G that is not connected has two or more connected components that
are disjoint and have G as their union.
Example: Connected component
How connected is a graph?
● Suppose that a graph represents a computer network. Knowing that this
graph is connected tells us that any two computers on the network can
communicate. However, we would also like to understand how reliable this
network is. For instance, will it still be possible for all computers to
communicate after a router or a communications link fails?
How connected is a graph?
● Suppose that a graph represents a computer network. Knowing that this
graph is connected tells us that any two computers on the network can
communicate. However, we would also like to understand how reliable this
network is. For instance, will it still be possible for all computers to
communicate after a router or a communications link fails?
● Sometimes the removal from a graph of a vertex and all incident edges
produces a subgraph with more connected components. Such vertices are
called cut vertices (or articulation points).
● The removal of a cut vertex from a connected graph produces a subgraph
that is not connected.
How connected is a graph?
● Sometimes the removal from a graph of a vertex and all incident edges
produces a subgraph with more connected components. Such vertices are
called cut vertices (or articulation points).
● The removal of a cut vertex from a connected graph produces a subgraph
that is not connected.
● Analogously, an edge whose removal produces a graph with more connected
components than in the original graph is called a cut edge or bridge.
● Note that in a graph representing a computer network, a cut vertex and a cut
edge represent an essential router and an essential link that cannot fail for all
computers to be able to communicate.
Example: Cut vertices and edges
Find the cut vertices and cut edges in the
graph G 1.
Example: Cut vertices and edges
Find the cut vertices and cut edges in the
graph G 1.

Soln: The cut vertices of G 1 are b, c, and e.


The removal of one of these vertices (and its
adjacent edges) disconnects the graph. The
cut edges are {a, b} and {c, e}. Removing
either one of these edges disconnects G 1 .
Nonseparable graphs
● Not all graphs have cut vertices. For example, the complete graph K n , where
n ≥ 3, has no cut vertices.
● When you remove a vertex from K n and all edges incident to it, what will be
the result?
Nonseparable graphs
● Not all graphs have cut vertices. For example, the complete graph K n , where
n ≥ 3, has no cut vertices.
● When you remove a vertex from K n and all edges incident to it, the resulting
subgraph is the complete graph K n−1 , a connected graph.
● Connected graphs without cut vertices are called nonseparable graphs, and
can be thought of as more connected than those with a cut vertex.
Connectedness in directed graphs
● There are two notions of connectedness in directed graphs, depending on
whether the directions of the edges are considered.
● A directed graph is strongly connected if there is a path from a to b and from
b to a whenever a and b are vertices in the graph.
● A directed graph is weakly connected if there is a path between every two
vertices in the underlying undirected graph.
● That is, a directed graph is weakly connected if and only if there is always a
path between two vertices when the directions of the edges are disregarded.
● Clearly, any strongly connected directed graph is also weakly connected.
Example: Connectivity in Directed Graphs
Are the directed graphs G and H shown in Figure 5 strongly connected? Are they
weakly connected?
Example: Connectivity in Directed Graphs
Are the directed graphs G and H shown in Figure 5 strongly connected? Are they
weakly connected?

Solution: G is strongly connected because there is a path between any two


vertices in this directed graph. Hence, G is also weakly connected.

The graph H is not strongly connected. There is no directed path from a to b in this
graph. However, H is weakly connected, because there is a path between any two
vertices in the underlying undirected

graph of H.
Strong Components of Directed graph
● The subgraphs of a directed graph G that are strongly connected but not
contained in larger strongly connected subgraphs, that is, the maximal
strongly connected subgraphs, are called the strongly connected components
or strong components of G.
● Example: The graph H in Figure has three strongly connected components,
consisting of the vertex a; the vertex e; and the subgraph consisting of the
vertices b, c, and d and edges (b, c), (c, d), and (d, b).
Application: Web Graph
● The Web graph represents Web pages with vertices and links with directed
edges. A snapshot of the Web in 1999 produced a Web graph with over 200
million vertices and over 1.5 billion edges.
● The underlying undirected graph of this Web graph is not connected, but it
has a connected component that includes approximately 90% of the vertices
in the graph.
● The subgraph of the original directed graph corresponding to this connected
component of the underlying undirected graph (that is, with the same vertices
and all directed edges connecting vertices in this graph) has one very large
strongly connected component and many small ones.
● The former is called the giant strongly connected component (GSCC) of the
directed graph. A Web page in this component can be reached following links
starting at any other page in this component. The GSCC in the Web graph
produced by this study was found to have over 53 million vertices.
Paths and Isomorphism
● There are several ways that paths and circuits can help determine whether
two graphs are isomorphic like the existence of a simple circuit of a particular
length is a useful invariant that can be used to show that two graphs are not
isomorphic.
● Example: Determine whether the graphs G and H shown in Figure are
isomorphic.
Paths and Isomorphism
● There are several ways that paths and circuits can help determine whether
two graphs are isomorphic like the existence of a simple circuit of a particular
length is a useful invariant that can be used to show that two graphs are not
isomorphic.
● Example: Determine whether the graphs G and H shown in Figure are
isomorphic.
● Solution: Both G and H have six vertices and
eight edges, and the degrees of vertices also agree.
However, H has a simple circuit of length three, namely, v
1 , v 2 , v 6 , v 1 , whereas G has no simple circuit of
length three. Because the existence of a simple
circuit of length three is an isomorphic invariant,
G and H are not isomorphic.
Counting Paths Between Vertices
● Let G be a graph with adjacency matrix A with respect to the ordering v 1 , v 2
, . . . , v n of the vertices of the graph (with directed or undirected edges, with
multiple edges and loops allowed).
● The number of different paths of length r from v i to v j , where r is a positive
integer, equals the (i, j )th entry of A^r .
Counting Paths Between Vertices
Example: How many paths of length four are there from a to d in the simple graph
G in Figure?
Counting Paths Between Vertices
Example: How many paths of length four are there from a to d in the simple graph
G in Figure?
Königsberg problem
● The town of Königsberg, Prussia was divided into four sections by the branches
of 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 eighteenth century seven bridges connected these regions.
● The townspeople took long walks through town on Sundays. They wondered
whether it was possible to start at some location in the town, travel across all the
bridges once without crossing any bridge twice, and return to the starting point.
Solution: Königsberg problem - Euler circuit
● The Swiss mathematician Leonhard Euler solved this problem. His solution,
published in 1736, may be the first use of graph theory.
● Euler studied this problem using the multigraph obtained when the four
regions are represented by vertices and the bridges by edges.
● 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 simple circuit in this multigraph that contains every edge?
● 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: Euler circuit or path
Which of the undirected graphs in Figure have an Euler circuit? Of those that do
not, which have an Euler path?
Example: Euler circuit or path
Which of the undirected graphs in Figure have an Euler circuit? Of those that do
not, which have an Euler path?

Solution: The graph G 1 has an Euler circuit, for example, a, e, c, d, e, b, a.


Neither of the graphs G 2 or G 3 has an Euler circuit. However, G 3 has an Euler
path, namely, a, c, d, e, b, d, a, b. G 2 does not have an Euler path.
Necessary and sufficient conditions for Eulerian
circuits and paths
● What can we say if a connected multigraph has an Euler circuit? What we
can show is that every vertex must have even degree ⇒ Euler’s
Theorem
● To do this, first note that 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, because the circuit enters via an edge incident with this
vertex and leaves via another such edge.
● Finally, the circuit terminates where it started, contributing one to deg(a).
Therefore, deg(a) must be even, because the circuit contributes one when it
begins, one when it ends, and two every time it passes through a (if it ever
does). A vertex other than a has even degree because the circuit contributes
two to its degree each time it passes through the vertex.
Applications: Eulerian circuits and paths
● Euler paths and circuits can be used to solve many practical problems. For
example, many applications ask for a path or circuit that traverses each street
in a neighborhood, each road in a transportation network, each connection in a
utility grid, or each link in a communications network exactly once.
● The problem of finding a circuit in a graph with the fewest edges that traverses
every edge at least once is known as the Chinese postman problem.
● Among the other areas where Euler circuits and paths are applied is in the
layout of circuits, in network multicasting, and in molecular biology, where Euler
paths are used in the sequencing of DNA.
Hamilton Paths and Circuits
● A simple path in a graph G that passes through every vertex exactly once is
called a Hamilton path, and a simple circuit in a graph G that passes through
every vertex exactly once is called a Hamilton circuit.
● That is, the simple path x 0 , x 1 , . . . , x n−1 , x n in the graph G = (V , E) is a
Hamilton path if V = {x 0 , x 1 , . . . , x n−1 , x n } and x i ≠ x j for 0 ≤ i < j ≤ n,
and the simple circuit x 0 , x 1 , . . . , x n−1 , x n , x 0 (with n > 0) is a Hamilton
circuit if x 0 , x 1 , . . . , x n−1 , x n is a Hamilton path.
Conditions for Hamiltonian Paths and Circuits
● Is there a simple way to determine whether a graph has a Hamilton circuit or
path?
Conditions for Hamiltonian Paths and Circuits
● Is there a simple way to determine whether a graph has a Hamilton circuit or
path? At first, it might seem that there should be an easy way to determine
this, because 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 circuits. However, many theorems are known that
give sufficient conditions for the existence of Hamilton circuits. Also, certain
properties can be used to show that a graph has no Hamilton circuit.
Applications of Hamilton Circuits
● Hamilton paths and circuits can be used to solve practical problems. For
example, many applications ask for a path or circuit that visits each road
intersection in a city, each place pipelines intersect in a utility grid, or each
node in a communications network exactly once.
● Finding a Hamilton path or circuit in the appropriate graph model can solve
such problems. The famous traveling salesperson problem or TSP (also
known in older literature as the traveling salesman problem) asks for the
shortest route a traveling salesperson should take to visit a set of cities. This
problem reduces to finding a Hamilton circuit in a complete graph such that
the total weight of its edges is as small as possible.
Shortest Path Problem
● Many problems can be modeled using graphs with weights assigned to their
edges. As an illustration, consider how an airline system can be modeled. We
set up the basic graph model by representing cities by vertices and flights by
edges.
Shortest Path Problem
● Many problems can be modeled using graphs with weights assigned to their
edges. As an illustration, consider how an airline system can be modeled. We
set up the basic graph model by representing cities by vertices and flights by
edges.
● Problems involving distances can be modeled by assigning distances
between cities to the edges.
● Problems involving flight time can be modeled by assigning flight times to
edges.
● Problems involving fares can be modeled by assigning fares to the edges.
Illustrative examples
Weighted Graphs
● Graphs that have a number assigned to each edge are called weighted
graphs.
● Weighted graphs are used to model computer networks. Communications
costs (such as the monthly cost of leasing a telephone line), the response
times of the computers over these lines, or the distance between computers,
can all be studied using weighted graphs.
● Determining a path of least length between two vertices in a network is one
such problem. To be more specific, let the length of a path in a weighted
graph be the sum of the weights of the edges of this path.
● The question is: What is a shortest path, that is, a path of least length,
between two given vertices?
Illustrative examples
A Shortest-Path Algorithm - Dijkstra’s Algorithm
Given a weighted graph G, the objective is to find the shortest path from a given source
vertex to all other vertices of G. The graph has the following characteristics-
● Set of vertices V
● Set of weighted edges E such that (q,r) denotes an edge between vertices q and r
and cost(q,r) denotes its weight.

It is a greedy algorithm. The main logic of this algorithm is based on the following
formula- dist[r]=min(dist[r], dist[q]+cost[q][r]).
This formula states that distance vertex r, which is adjacent to vertex q, will be
updated if and only if the value of dist[q]+cost[q][r] is less than dist[r].
Dijkstra's Algorithm
Step 1; Set dist[s]=0, S=ϕ // s is the source vertex and S is a 1-D array having all
the visited vertices

Step 2: For all nodes v except s, set dist[v]= ∞

Step 3: find q not in S such that dist[q] is minimum // vertex q should not be visited

Step 4: add q to S // add vertex q to S since it has now been visited

Step 5: update dist[r] for all r adjacent to q such that r is not in S //vertex r should
not be visited dist[r]=min(dist[r], dist[q]+cost[q][r]) //Greedy and Dynamic approach

Step 6: Repeat Steps 3 to 5 until all the nodes are in S // repeat till all the vertices
have been visited

Step 7: Print array dist having shortest path from the source vertex u to all other
vertices
Example:
Example:
Example:
Example:
Example:
Recap
More about shortest path problem
More algorithms:

● Dijkstra's algorithm solves the single-source shortest path problem with


non-negative edge weight.
● Bellman–Ford algorithm solves the single-source problem if edge weights
may be negative.
● A* search algorithm solves for single-pair shortest path using heuristics to
try to speed up the search.
● Floyd–Warshall algorithm solves all pairs shortest paths.
● Johnson's algorithm solves all pairs shortest paths, and may be faster than
Floyd–Warshall on sparse graphs.
Famous application: Travelling Salesperson problem
Motivation: Graph Coloring
● Problems related to the coloring of maps of regions, such as maps of parts of
the world, have generated many results in graph theory.
● When a map is colored, two regions with a common border are customarily
assigned different colors. One way to ensure that two adjacent regions never
have the same color is to use a different color for each region. However, this
is inefficient, and on maps with many regions it would be hard to distinguish
similar colors. Instead, a small number of colors should be used whenever
possible.
● Consider the problem of determining the least number of colors that can be
used to color a map so that adjacent regions never have the same color.
Dual graphs
● Each map in the plane can be
represented by a graph. To set up this
correspondence, each region of the map
is represented by a vertex.
● Edges connect two vertices if the regions
represented by these vertices have a
common border. Two regions that touch
at only one point are not considered
adjacent. The resulting graph is called
the dual graph of the map.
Graph Coloring
● The problem of coloring the regions of a map is equivalent to the problem of
coloring the vertices of the dual graph so that no two adjacent vertices in this
graph have the same color.
● A coloring of a simple graph is the assignment of a color to each vertex of
the graph so that no two adjacent vertices are assigned the same color.
Graph Coloring
● The problem of coloring the regions of a map is equivalent to the problem of
coloring the vertices of the dual graph so that no two adjacent vertices in this
graph have the same color.
● A coloring of a simple graph is the assignment of a color to each vertex of
the graph so that no two adjacent vertices are assigned the same color.
● A graph can be colored by assigning a different color to each of its vertices.
However, for most graphs a coloring can be found that uses fewer colors than
the number of vertices in the graph. What is the least number of colors
necessary?
Graph Coloring
● The problem of coloring the regions of a map is equivalent to the problem of
coloring the vertices of the dual graph so that no two adjacent vertices in this
graph have the same color.
● A coloring of a simple graph is the assignment of a color to each vertex of
the graph so that no two adjacent vertices are assigned the same color.
● A graph can be colored by assigning a different color to each of its vertices.
However, for most graphs a coloring can be found that uses fewer colors than
the number of vertices in the graph. What is the least number of colors
necessary?
● The chromatic number of a graph is the least number of colors needed for a
coloring of this graph. The chromatic number of a graph G is denoted by χ(G).
Examples:
What are the chromatic numbers of the graphs G and H?
Examples:
What are the chromatic numbers of the graphs G and H?
Graph Homomorphism
● A graph homomorphism is a mapping between two graphs that respects
their structure. More concretely, it is a function between the vertex sets of two
graphs that maps adjacent vertices to adjacent vertices. Homomorphisms
generalize various notions of graph colorings.
Graph Homomorphism
● A graph homomorphism is a mapping between two graphs that respects
their structure. More concretely, it is a function between the vertex sets of two
graphs that maps adjacent vertices to adjacent vertices. Homomorphisms
generalize various notions of graph colorings.
● A graph homomorphism f from a graph G = (V(G), E(G)) to a graph H =
(V(H), E(H)), written as f : G → H is a function from V(G) to V(H) that maps
endpoints of each edge in G to endpoints of an edge in H. Formally, {u,v} ∈
E(G) implies {f(u),f(v)} ∈ E(H), for all pairs of vertices u, v in V(G).
Graph Homomorphism
● A graph homomorphism f from a graph G = (V(G), E(G)) to a graph H =
(V(H), E(H)), written as f : G → H is a function from V(G) to V(H) that maps
endpoints of each edge in G to endpoints of an edge in H. Formally, {u,v} ∈
E(G) implies {f(u),f(v)} ∈ E(H), for all pairs of vertices u, v in V(G).
● If there exists any homomorphism from G to H, then G is said to be
homomorphic to H or H-colorable. This is often denoted as just: G → H .
● There is an injective homomorphism from G to H (i.e., one that never maps
distinct vertices to one vertex) if and only if G is a subgraph of H.
● If a homomorphism f : G → H is a bijection (a one-to-one correspondence
between vertices of G and H) whose inverse function is also a graph
homomorphism, then f is a graph isomorphism.
Chromatic Number Results
● Graph coloring is computationally hard.
● The best algorithms known for finding the chromatic number of a graph have
exponential worst-case time complexity (in the number of vertices of the
graph).
● Even the problem of finding an approximation to the chromatic number of a
graph is difficult. It has been shown that if there were an algorithm with
polynomial worst-case time complexity that could approximate the chromatic
number of a graph up to a factor of 2 (that is, construct a bound that was no
more than double the chromatic number of the graph), then an algorithm with
polynomial worst-case time complexity for finding the chromatic number of the
graph would also exist.
Applications: Graph Coloring
● Scheduling Final Exams: How can the final exams at a university be
scheduled so that no student has two exams at the same time?
Applications: Graph Coloring
● Scheduling Final Exams: How can the final exams at a university be
scheduled so that no student has two exams at the same time?
○ This scheduling problem can be solved using a graph model, with
vertices representing courses and with an edge between two vertices if
there is a common student in the courses they represent. Each time slot
for a final exam is represented by a different color. A scheduling of the
exams corresponds to a coloring of the associated graph.
Applications: Graph Coloring
● Frequency Assignments: Television channels 2 through 13 are assigned to
stations in North America so that no two stations within 150 miles can operate
on the same channel. How can the assignment of channels be modeled by
graph coloring?
Applications: Graph Coloring
● Frequency Assignments: Television channels 2 through 13 are assigned to
stations in North America so that no two stations within 150 miles can operate
on the same channel. How can the assignment of channels be modeled by
graph coloring?
○ Construct a graph by assigning a vertex to each station. Two vertices are
connected by an edge if they are located within 150 miles of each other.
An assignment of channels corresponds to a coloring of the graph, where
each color represents a different channel.
References
[1] Chapter 10, 11 [KR]
[2] Chapter 6 [BDS]
[3] Chapter 1, 2 [RD]

Note: All images unless cited are from one of the above sources

You might also like