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

Warshalls and Floyds

Uploaded by

Jami gnaneswari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Warshalls and Floyds

Uploaded by

Jami gnaneswari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

The Warshall’s Algorithm is for solving the All Pairs

Shortest Path problem. The problem is to find shortest


distances between every pair of vertices in a given
edge weighted directed Graph. Transitive closure of the
digraph, would allow us to determine in constant time whether the
jth vertex is reachable from the ith vertex.

DEFINITION: The transitive closure of a directed graph with n


vertices can be defined as the n × n Boolean matrix T = {tij }, in
which the element in the ith row and the jth column is 1 if there
exists a nontrivial path (i.e., directed path of a positive length) from
the ith vertex to the jth vertex; otherwise, tij is 0.
Warshall’s algorithm constructs the transitive closure through
a series of n × n Boolean Matrices: R(0) ,...,R(k−1) , R(k),...R(n). Each
of these matrices provides certain information about directed
paths in the digraph. Specifically, the element rij (k) in the ith row
and jth column of matrix R(k) (i, j = 1, 2, . . . , n, k = 0, 1,...,n) is
equal to 1 if and only if there exists a directed path of a
positive length from the ith vertex to the jth vertex with each
intermediate vertex, if any, numbered not higher than k.
Warshall followed the recurrence relation:
K<=3
K<=3
Floyd’s Algorithm for the All-Pairs Shortest-Paths Problem:

Given a weighted connected graph (undirected or directed), the all-pairs


shortest paths problem asks to find the distances—i.e., the lengths of the
shortest paths— from each vertex to all other vertices.

It is convenient to record the lengths of shortest paths in an n × n matrix


D called the distance matrix: the element dij in the ith row and the jth
column of this matrix indicates the length of the shortest path from the
ith vertex to the jth vertex.
Floyd’s algorithm computes the distance matrix of a weighted graph with n
vertices through a series of n × n matrices: D(0) ,...,D(k−1) , D(k),...,D(n)

Floyd used the following recurrence relation:

Where dij(k) is distance from vertex vi to vj with intermediate vertices


not more than k

You might also like