• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Spsp fw
 

Spsp fw

on

  • 241 views

 

Statistics

Views

Total Views
241
Views on SlideShare
241
Embed Views
0

Actions

Likes
0
Downloads
5
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Spsp fw Spsp fw Presentation Transcript

    • Single pair shortest path problem MD Tanvir Anwoar & Shajedur Rahman
    • Introduction: 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. This is analogous to the problem of finding the shortest path between two intersections on a road map: the graph's vertices correspond to intersections and the edges correspond to road segments, each weighted by the length of its road segment.
    • Application: * The traffic and length of the highways are path weights. * Vehicle routing problem solving * Solving network design problem * In video games, these algorithms are frequently used to find the shortest path between two points on a map Purpose of the problem solving: * Improve Quality of the service, Reducing time and cost
    • Problem solving methods : Dijkstra Algorithm : a. All edge weights should be non-negative b. Each iteration of Dijkstra takes O(n^2) for array-based or O(m log n) for heap-based c. Total complexity is either O(n^3) or O(mn log n) d. This is a case where just repeatedly using a solution to a simpler problem works out fine.
    • Problem solving methods : Bellman-Ford Algorithm: a. If some edge weights are negative b. It has complexity O(nm) for a single source c. Total sources solution is O(n^2 m), which is O(n4) for dense graphs
    • Problem solving methods : Floyd-Warshall Algorithm : a. If some edge weights are negative b. Dynamic programming solution to compute all sources shortest paths c. Works with negative weights (or without) – we assume no negative cycles d. Complexity O(n^3)
    • Floyd-Warshall Algorithm 1. Graph should be directed 2. It may contain negative edges but no negative cycle 3. Find the shortest path between all the pairs of nodes A B
    • Floyd-Warshall Algorithm 1. Graph should be directed 2. It may contain negative edges but no negative cycle 3. Find the shortest path between all the pairs of nodes -2 A B -1
    • Floyd-Warshall Algorithm Example : 1 2 4 3
    • Floyd-Warshall Algorithm Example : 1 4 D 1 1,4 = 2 3
    • Floyd-Warshall Algorithm Example : 1 4 D 1 1,4 2 3 = 1 ,2,4
    • Floyd-Warshall Algorithm Example : 1 4 D 1 1,4 2 3 = 1 ,2,4 ; 1,4
    • Floyd-Warshall Algorithm matrix formation : D (k) { min (D if k>= 1 (k-1) (I,j) = (I,j)) , D (k-1) (I,k ) + D (k-1) (k,j) }
    • Floyd-Warshall Algorithm matrix formation : 3 1 2 -4 7 4 8 5 3 1 2 6 4 -5 0 X X 2 X 3 0 4 X X D(0) 8 X X 1 0 X -5 1 X 0 -4 7 -4 7 0
    • Floyd-Warshall Algorithm matrix formation : 3 1 2 -4 7 4 8 5 3 1 0 X X 2 X 3 0 4 X X D(0) 8 X X 11 0 X -5 1 X 0 2 6 D (0) 4 -5 (2,4) =1 -4 7 -4 7 0
    • Floyd-Warshall Algorithm matrix formation : 3 1 2 -4 7 4 8 5 3 1 2 6 0 X X 2 X 3 0 4 5 X D(1) 8 X X 1 0 X -5 0 X 6 -4 7 X -2 -2 0 Adjacency Matrix 4 -5 D (1) (4,5) = -2
    • Floyd-Warshall Algorithm matrix formation : 3 1 2 -4 7 4 8 5 3 1 2 6 0 3 7 2 8 1 0 4 -1 5 D(5) -3 2 -4 1 -4 0 5 -5 0 1 6 -4 -1 3 -2 0 Adjacency Matrix 4 -5 D (5) (2,3) = -4
    • Floyd-Warshall Algorithm Pseudocode: 1. For i=1 to |V| do 2. For j=1 to |V| do 3. S[i,j,0] = w(i,j) 4. For k=1 to |V| do 5. For i=1 to |V| do 6. For j=1 to |V| do 7. S[i,j,k] = min { 8. S[i,j,k-1], 9. S[i,k,k-1]+S[k,j,k-1] } 10. Return S[:,:,n] # return 2d array with n = |V|
    • Floyd-Warshall Algorithm