Professional Documents
Culture Documents
CJB0911008 T.srinivas
CJB0911008 T.srinivas
Srinivas.T
CJB0911008 M. Sc. (Engg.) in Computer Science And Engineering
Module Leader: N D Gangadhar Module Name: Data Structures and Algorithm Module Code :CSN501
M. S. Ramaiah School of Advanced Studies
MAX MARKS TECHNICAL CONTENT GRASP AND EXPLANATION SLIDE PRESENTATION Q&A TOTAL 10 10 10 10 40
SCORE
Agenda
Introduction to Floyd-Warshall Algorithm. Storing a Weighted, Directed Graph. Difference between Dijkstras & Floyds algorithm Floyd-Warshall Algoritm explanation.
Introduction The Floyd-Warshall Algorithm is a simple and widely used algoritm to compute shortest paths between all pairs of vertices in an edge weighted directed graph. The Floyd-Warshall Algorithm is also known as Roy-Warshall Algorithm ,Floyds Algorithm,or Roy-Floyd Algorithm. The Floyd-Warshall Algoithm improves upon this algorithm running in O(n^3).
M. S. Ramaiah School of Advanced Studies
Introduction
contd.. contd..
The algorithm is an example of dynamic programming, a method of solving problems where one needs to find the best decision one after another. Graph can have negative weights, but not negative weight cycles. A weighted, directed graph is a collection vertices connected by weighted edges (where the weight is some real number).
M. S. Ramaiah School of Advanced Studies
Introduction
contd.. contd..
One of the most common examples of a graph in the real world is a road map. Each location is a vertex and each road connecting locations is an edge. We can think of the distance traveled on a road from one location to another as the weight of that edge.
General Example
Ipoh Ipoh Miri Shalam Miri Shahlam
0 1.5 4
1.7 0 2.5
3.5 0
Ipoh
1.5 1.7
Miri
3.5
4 Shalam
2.5
7
D=
0 1 2 3
0 0
1 6 0
2 5 4 0
3 3 2 0
6 0
1 4
3 3 2
5 2
k i
M. S. Ramaiah School of Advanced Studies
j
10
Consider Vertex 1: D(3,2) = D(3,1) + D(1,2) Consider Vertex 2: D(1,3) = D(1,2) + D(2,3) Consider Vertex 3: Nothing changes
11
12
13
14
15
Applications The Floyd-Warshal Algorithm can be used to solve the following problems among are Inversion of real matrices(Guass-Jordan algorithm). Testing whether an undirected graph is bipartite. Fast computation of pathfinder network. Shortest pats in directed graphs.
M. S. Ramaiah School of Advanced Studies
16
Draw backs The Floyd-Warshal Algorithm outputs the correct result as long as no negative cycle exist in the the input graph. In case that a negative cycle exists computing a shortest path is an Np-hard problem and the Floyd-Warshal Algorithm will not output the correct result.
17
Summary The Floyds algorithm is used to solve the all-pairs shortest paths problem on a directed graph G=(V,E). This algorithm has a worst case runtime of O(n^3) The Floyds algorithm is a dynamic programming algorithm
18
References
[1]CormenThomasH;Leiserson,Charles, Rivest,Ronaldl(1990) Introduction to Algorithm(1st ed.).Mit press &McGrawHill [2]http://en.wikipedia.org/wiki/Floyd%E2%80%93Warshall _algorithm#Algorithm ;
19
QUERIES ?
20
21
22