Download as pdf or txt
Download as pdf or txt
You are on page 1of 53

DISCRETE

MATHEMATICS
,
Graph:

A graph (denoted as $G = (V, E)$) consists of a non-empty set of vertices


or nodes V and a set of edges E.
Types of graph

■ Simple graph
■ Null graph
■ Multi graph
■ Directed and Undirected graph
■ Regular graph
■ Cycle graph
■ Complete graph
■ Bipartite graph
■ Complete Bipartite graph
Conti..

■ Directed and Undirected graph


A graph G = (V, E) is called a directed
graph if the edge set is made of ordered
vertex pair and a graph is called undirected
if the edge set is made of unordered vertex
pair.
Conti..

■ Null graph
A null graph has no edges.
The null graph of $n$ vertices is
denoted by $N_n$.

■ Multi graph
If in a graph multiple edges between
the same set of vertices are allowed,
it is called Multi graph.
Conti..

■ Simple graph
A graph is called simple graph
if the graph is undirected and does not
contain any loops or multiple edges.
Conti..

■ Complete graph
A graph is called complete graph
if every two vertices pair are joined by
exactly one edge.
Conti..

■ Regular graph
A graph is regular if all the vertices
of the graph have the same degree.
■ Cycle graph
If a graph consists of a single cycle,
it is called cycle graph.
Conti..

■ Bipartite graph
If the vertex-set of a graph G can
be split into two disjoint sets, in such
a way that each edge in the graph joins
a vertex and there are no edges in G that
connect two vertices , then the graph G is
called a bipartite graph.
Conti..

■ Complete Bipartite graph


A complete bipartite graph is a
bipartite graph in which each vertex
in the first set is joined to every single
vertex in the second set.
Representing Graph:

There are mainly two ways to represent a graph.


i. Adjacency Matrix
ii. Adjacency List

– List all the edges of the graph (no multiple edges)

– Use adjacency list, which specifies the vertices that are adjacent to each
vertex of the graph.
Adjacency List:

– Example: Use adjacency lists to describe


b this simple graph.

a c

e d

Solution:
Adjacency Matrix:

– To simplify computation, graphs can be represented using matrices


– Example: Use a adjacency matrix to represent this graph:
a b

c d
Solution:
We order the vertices a, b, c, d. The matrix representing this graph is
0 1 1 1
1 0 1 0 

1 1 0 0
 
1 0 0 0
Graph Isomorphism:

Definition:
– The simple graphs G1 and G2 are isomorphic if there is a one-to-one and onto
function f from V1 to V2 with the property that a and b are adjacent in G1 if and
only if f(a) and f(b) are adjacent in G2, for all a and b in V1. Such a function f is
called an isomorphism.
– Example:
Properties:

Two isomorphic simple graphs must both have.


For example, they must have
•the same number of vertices,
• the same number of edges, and
• the same degrees of vertices.
•Note that two graphs that differ in any of these invariants are not isomorphic, but
two graphs that match in all of them are not necessarily isomorphic.
Example:
– Example: Show that the graphs G = (V,E) and H = (W,F) are isomorphic
u1 u2 v1 v2

u3 u4 v3 v4
G H
– Solution: The function f with f(u1) = v1, f(u2) = v4, f(u3) = v3, 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(u3) = v3, and f(u1) = v1 and f(u4) = v2 are adjacent in H.
Example:
■ Example II: How about these two graphs?
a a
b
e e
b
c c d
d
■ Solution: No, they are not isomorphic, because they differ in the degrees
of their vertices.
■ Vertex d in right graph is of degree one, but there is no such vertex in the
left graph.
Connected Graph:

 A graph is connected when there is a path between every pair of vertices.


 A graph that is not connected is disconnected. A graph G is said to
be disconnected if there exist two nodes in G such that no path in G.
History:
Seven Bridges of Königsberg:
■ A recreational mathematical puzzle, set in the old Prussian city of Königsberg
(now Kaliningrad, Russia), that led to the development of the branches of mathematics
known as graph theory. In the early 18th century, the citizens of Königsberg spent their
days walking on the intricate arrangement of bridges across the waters of the Pregel
(Pregolya) River, which surrounded two central landmasses connected by a bridge (3).
Additionally, the first landmass (an island) was connected by two bridges (5 and 6) to
the lower bank of the Pregel and also by two bridges (1 and 2) to the upper bank, while
the other landmass (which split the Pregel into two branches) was connected to the lower
bank by one bridge (7) and to the upper bank by one bridge (4), for a total of seven
bridges. According to folklore, the question arose of whether a citizen could take a walk
through the town in such a way that each bridge would be crossed exactly once.
Conti…
Solution:

■ Leonhard Euler, first graph theory father, said in order to solve this puzzle I want
the degree of every vertex must be even but here you see the degree of every
vertex is odd, hence I proved there exists no solution for this graph and hence I
solved the problem.
Euler path:

■ An Euler path is a path that uses every edge of a graph exactly once.
■ Vertex can be repeated but edge can’t.
■ An Euler path starts and ends at
different vertices.
■ Graph contain 2 vertices with odd degree.
Euler circuit:

■ An Euler circuit is a circuit that uses every edge of a graph exactly once.
■ An Euler circuit starts and ends at the same vertex.
Euler graph:

■ An Euler graph is a cycle that uses each edge exactly once.


■ A graph contains a Euler circuit /cycle is called Euler graph.
■ Contain even number of vertices.
Numerical examples:
Conti…
Conti..
HAMILTON PATH
Presentation
Icosian game

■ The icosain game is a mathematical game invented in 1857 by William rowan


hamilton.
■ The game’s object is finding a Hamilton cycle along the edges of dodecahedron
such that every vertex is visited a single time,
■ No edge is visited twice, and ending point is the same as the starting point.
Icosian game
Hamilton path

■ A Hamilton path is a path that visit each vertices exactly once.


■ A Hamilton path is a path through each vertex that doesn't end where it started
is a Hamilton path.

.
Hamilton cycle or circuit

A cycle that visit each vertex exactly once except for the vertex that start and end
both, which is visit twice.
Hamilton path and circuit

■ circuit.

Hamilton path Hamilton circuit


Hamilton cycle exist or not

■ If the articulation point exist in the graph Hamiltonian cycle not exist.
■ If the graph have pendent vertices in the graph Hamiltonian cycle not exist
What is a Path ?
■ A path is a sequence of edges that begins at a vertex, and travels
from vertex to vertex along edges of the graph. The number of
edges on the path is called the length of the path.

■ Ex :
■ Consider the graph on the right. w  x  y  z  x
corresponds

w x

y z
Conti..

w x

• If a path begins and ends at the same vertex, the


path is also called a circuit.
y z
• Ex : Consider the graph on the right.
■ w  x  y  z  w gives to a
circuit of length 4
Paths and Connected Components
■ An undirected graph is connected if there is a path between any
pair of vertices. Otherwise, it is disconnected.

Connected Disconnected
SHORTEST
PATH
PROBLEM
SHORTEST PATH
PROBLEM :
 The shortest path problem is the problem of finding
a path between two vertices in a graph such that
the sum of the weights of its constituent edges is
minimized.


SHORTEST PATH PROBLEM:

 Given the graph below, suppose we wish to


find the shortest path from vertex 1 to vertex
13.
SHORTEST PATH EXAMPLE:
 Given:
 Weighted Directed graph G = (V, E).
 Source s, destination t.
 Find shortest directed path from s to t.

2 23 3
9
s
18
2 6 Cost of path s-2-3-5-t
14 6 = 9 + 23 + 2 + 16
30
11
4
19
= 48.
5
5
15 6
20
16
t
7 44
DIJKSTRA’S ALGORITHM:
 Works when all of the weights are positive.
 Provides the shortest paths from a source to
all other vertices in the graph.
 Can be terminated early once the shortest
path to t is found if desired.
EXAMPL
E : vertex 1 and update its neighbours,
 Visit
marking it as visited
 the shortest paths to 2, 4, and 5 are
updated
EXAMPL
EThe
 : next vertex we visit is vertex 4
 vertex 5 1 + 11 ≥ 8 don’t update
 vertex 7 1+ 9<∞ update
 vertex 8 1+ 8<∞ update
EXAMPL
ENext,
: visit vertex 2
 vertex 3 4+1<∞ update
 vertex 4 already
visited
 vertex 5 4+6≥8 don’t update
 vertex 6 4+1<∞ update
EXAMPL
ENext,
: we have a choice of either 3 or 6
 We will choose to visit 3
 vertex 5 5+2<8 update
 vertex 6 5+5≥5 don’t update
EXAMPL
E:We then visit 6

 vertex 8 5+7≥9 don’t update


 vertex 9 5+8<∞ update
EXAMPL
ENext,
: we finally visit vertex 5:
 vertices 4 and 6 have already been visited
 vertex 7 7 + 1 < 10 update
 vertex 8 7+1< 9 update
 vertex 9 7 + 8 ≥ 13 don’t update
EXAMPLE:
 Given a choice between vertices 7 and 8, we
choose vertex 7
 vertices 5 has already been visited
 vertex 8 8+2≥8 don’t update
EXAMPL
ENext,
: we visit vertex 8:
 vertex 9 8 + 3 < 13 update
EXAMPL
EFinally,
 : we visit the end vertex
 Therefore, the shortest path from 1 to 9 has length
11
EXAMPL
EWe
: can find the shortest path by working back from
the final vertex:
 9, 8, 5, 3, 2, 1
 Thus, the shortest path is (1, 2, 3, 5, 8, 9)

You might also like