Your SlideShare is downloading. ×
Spsp fw
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Spsp fw

105

Published on

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
105
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
10
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Single pair shortest path problem MD Tanvir Anwoar & Shajedur Rahman
  • 2. 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.
  • 3. 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
  • 4. 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.
  • 5. 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
  • 6. 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)
  • 7. 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
  • 8. 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
  • 9. Floyd-Warshall Algorithm Example : 1 2 4 3
  • 10. Floyd-Warshall Algorithm Example : 1 4 D 1 1,4 = 2 3
  • 11. Floyd-Warshall Algorithm Example : 1 4 D 1 1,4 2 3 = 1 ,2,4
  • 12. Floyd-Warshall Algorithm Example : 1 4 D 1 1,4 2 3 = 1 ,2,4 ; 1,4
  • 13. 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) }
  • 14. 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
  • 15. 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
  • 16. 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
  • 17. 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
  • 18. 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|
  • 19. Floyd-Warshall Algorithm

×