Sunteți pe pagina 1din 13

BITS, PILANI K. K.

BIRLA GOA CAMPUS

Dr. Tarkeshwar Singh


Department of Mathematics
Topics to be covered
Directed Graphs
Connectivity in digraphs
Shortest paths in digraphs
Dijkstras Algorithm
Floyd-Warshall Algorithm.

15-04-2017 BITS, PILANI K. K. BIRLA GOA 2


CAMPUS
Directed Graphs
Definition: A directed graph (or digraph in short) D
consists of a nonempty finite set V of objects called
vertices and a set A of ordered pair of distinct vertices
called directed edges or arcs of D.
A digraph is also referred as oriented graph, which is
obtained from G by orienting the edges of G.
A digraph D in which at most one of the arc (u, v) and
(v, u) arcs is present is called an oriented graph.
If (u,v) is an arc then u is called the initial vertex and v
is called terminal vertex.
15-04-2017 BITS, PILANI K. K. BIRLA GOA CAMPUS 3
Digraphs Contd.
Degree: There are two different types of degree in a
digraph D.
In-degree: The in-degree of a vertex v is the number
of arcs incoming to v and is denoted by d-(v).
Out-degree: The out-degree of a vertex v is the
number of arcs going out from v and is denoted by
d+(v).

15-04-2017 BITS, PILANI K. K. BIRLA GOA 4


CAMPUS
Digraphs Contd.
Adjacency matrix of a (p, q)-digraph G is a
square matrix A(D) = [ai,j ] of order p p,
where ai,j = 1 if uiuj E and 0 otherwise.
The adjacency matrix occurs in many
different disciplines and therefore it is known
as transition matrix(sequential machine),
relation or connection matrix(networks),
performance matrix(social networks) etc.

15-04-2017 BITS, PILANI K. K. BIRLA GOA 5


CAMPUS
Digraphs contd.

Theorem: If D is a digraph of order n and size m


with vertex set V(D) = {v1,v2,,vn} the sum of in-
degree = sum of out-degree = # arcs in D.
Connectedness: There are two types of
connected digraph.
Weakly connected: A digraph D is said to be
weakly connected if its underlying graph is
connected.

15-04-2017 BITS, PILANI K. K. BIRLA GOA 6


CAMPUS
Digraphs Contd.
Strongly connected: A digraph D is said
to be strongly connected if every vertex
reachable from any other vertices.
Diwalk: A sequence of vertices and arcs
W = u = u0,u1,,uk = v such that uiui+1 A(D),
where 1 i k-1.
Ditrail: A diwalk without repetition of arcs.
Dicircuit: A closed ditrail 2.
15-04-2017 BITS, PILANI K. K. BIRLA GOA 7
CAMPUS
Digraphs Contd.
Dipath: A diwalk without repetition of
vertices.
Dicycle: A closed dipath 2.
Theorem: If there is a (u,v)-diwalk of length
l in a digraph D then there is a dipath of
length at most l.
Theorem: A digraph is strong if and only if D
has a closed spanning dicircuit.
15-04-2017 BITS, PILANI K. K. BIRLA GOA 8
CAMPUS
Digraphs Contd.
Shortest Path: A di-path of a digraph D
which contains leas number of arcs of D
between any pair of vertices.
The number of arcs in a shortest path is
known as shortest distance.

15-04-2017 BITS, PILANI K. K. BIRLA GOA 9


CAMPUS
Dijkstras Algorithm
Input: A weighted digraph D = (V, A, w) and a
source vertex as s = 1 V.
Output: A shortest path from 1 to all vertices.
Initialize: V = {1,2,, n}.
Step-1: U = {2,3,n};
For i = 2 to n
Path-cost array[i] = w1i
For i = 1 to n-2
15-04-2017 BITS, PILANI K. K. BIRLA GOA 10
CAMPUS
Digraphs Contd.
Umin = {x | x U and path-cost[x] is
minimum};
v = an element from Umin;
U = U \{v}
Step-2: for every u U
Do the path-cost[u] = min{path-cost[u], path-
cost[v]+wvu}
Stop whenever implementation is not possible.
15-04-2017 BITS, PILANI K. K. BIRLA GOA 11
CAMPUS
Floyd-Warshall Algorithm
Let distance be a |V| |V| array of minimum distances initialized to
(infinity).
for each vertex v;
dist[v][v] 0
for each edge (u, v);
dist[u][v] w(u,v) the weight of the edge (u,v)
for k from 1 to |V|
for i from 1 to |V|
for j from 1 to |V|
if dist[i][j] > dist[i][k] + dist[k][j]
dist[i][j] dist[i][k] + dist[k][j]
end if
15-04-2017 BITS, PILANI K. K. BIRLA GOA 12
CAMPUS
Thanks

BITS, PILANI K. K. BIRLA GOA CAMPUS 13

S-ar putea să vă placă și