Sie sind auf Seite 1von 10

Presentation on:

Floyed Warshall-Algorithm
Subject:
Data structure & Algorithm
Submitted by:
Nawsher Ali
1864114`
Abrar Khan
1864106
Ashfaq Ahmad
1864108
Semester: 2nd
Submitted to:
Mr. Anwar Rashad
Govt AKL PG College Matta Swat
Department of Computer Science

Date: May 24, 2019


Requarments

Graph must
There
be a weighted
should be no
directed Egde weight negative
graph must be cycle
negative or
positive.
Shortest path problem:
□ In graph theory , the shortest path problem is the problem of finding a path between
two vertices or nodes in a graph such that the sum of the weights of its constituent
edges is minimized.
□ The problem is also sometime called the single-pair shortest path problem to
distinguish it from the following variation.
a) single-source shortest path problem .
b) Single-destination shortest path problem. 1
c) All pairs shortest path problems. 1 2

2 3

3 7
4
𝐾
𝑑𝐼𝐽 =weight of shortest path from vertex I to j for which all intermediate
node(vertices) are in {1,2,3, . . . k }
𝐾
𝑑𝐼𝐽 = 𝑤𝑖𝑗 if k=0

𝐾−1 𝐾−1 𝐾−1


min (𝑑𝐼𝐽 , 𝑑𝐼𝑘 + 𝑑𝑘𝐽 if k >= 1)

0 𝑖𝑓 𝑖 = 𝑗
𝑚
For VxV matrix 𝐷𝑚 = 𝑑𝐼𝐽 and 𝑑𝑖𝑗 = ቐ 𝑤𝑖𝑗 𝑖𝑓 𝑖 ! = 𝑗
inf 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
Algorithm
Let v=number of vertices in graph.
Let dist = V x V array of minimum distance.
For each vertex V
Dist [v][v] = 0
For each edge (u,v) = weight (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]
}
}
i->rows
J->colums
Problem
• Use Floyd-Warshal algorithm to find the shortest path between every pair of vertices in the following graph.

1 8
4
4 2
2

9 1

Das könnte Ihnen auch gefallen