1 / 44

Dijkstra, Warshall-Floyd

Dijkstra, Warshall-Floyd. Presented by Eddy Chan. Introduction. Shortest Path Algorithms Requirements Properties (Complexity in coding and runtime, Advantages & Disadvantages etc.). BFS. BFS can be used to find the shortest path from a source to destinations. S. T. S. T. S. T. S. T.

jethro
Download Presentation

Dijkstra, Warshall-Floyd

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Dijkstra, Warshall-Floyd Presented by Eddy Chan

  2. Introduction • Shortest Path Algorithms • Requirements • Properties (Complexity in coding and runtime, Advantages & Disadvantages etc.)

  3. BFS • BFS can be used to find the shortest path from a source to destinations

  4. S T

  5. S T

  6. S T

  7. S T

  8. S T

  9. DFS • DFS can also be used to find the shortest path

  10. S T

  11. S T

  12. S T

  13. S T

  14. S T

  15. S T

  16. S T

  17. S T

  18. S T

  19. S T

  20. S T

  21. S T

  22. Dijkstra Algorithm for each i , d[i] ← ∞ d[s] ← 0 u ← s whilenot (u == t) do for eachvwhere (u, v) in E if d[v] > d[u] + wuvthen d[v] = d[u] + wuv u ← v , where v is not used before and d[v] is min

  23. Dijkstra Algorithm for each i , d[i] ← ∞ d[s] ← 0 u ← s whilenot (u == t) do for eachvwhere (u, v) in E if d[v] > d[u] + wuvthen d[v] = d[u] + wuv p[v] = u u ← v , where v is not used before and d[v] is min

  24. 3 3 3 2 S 2 T 3 2 1 3 3 3 3 2

  25. A 3 E 3 3 B 2 S F 2 T 3 2 0 S 0 A I B I C I D I E I F I G I H I T I 1 3 C G 3 3 D 3 H 2

  26. A 3 E 3 3 B 2 S F 2 T 3 2 0 1 S 0 0 A I 3 B I 2 C I I D I 3 E I I F I I G I I H I I T I I 1 3 C G 3 3 D 3 H 2

  27. A 3 E 3 3 B 2 S F 2 T 3 2 0 1 2 S 0 0 A I 3 3 B I 2 C I I 4 D I 3 3 E I I I F I I I G I I I H I I I T I I I 1 3 C G 3 3 D 3 H 2

  28. A 3 E 3 3 B 2 S F 2 T 3 2 0 1 2 3 S 0 0 A I 3 3 B I 2 C I I 4 4 D I 3 3 3 E I I I 6 F I I I I G I I I I H I I I I T I I I I 1 3 C G 3 3 D 3 H 2

  29. A 3 E 3 3 B 2 S F 2 T 3 2 0 1 2 3 4 S 0 0 A I 3 3 B I 2 C I I 4 4 4 D I 3 3 3 E I I I 6 6 F I I I I I G I I I I I H I I I I 5 T I I I I I 1 3 C G 3 3 D 3 H 2

  30. A 3 E 3 3 B 2 S F 2 T 3 2 0 1 2 3 4 5 S 0 0 A I 3 3 B I 2 C I I 4 4 4 D I 3 3 3 E I I I 6 6 6 F I I I I I 7 G I I I I I 7 H I I I I 5 5 T I I I I I I 1 3 C G 3 3 D 3 H 2

  31. A 3 E 3 3 B 2 S F 2 T 3 2 0 1 2 3 4 5 6 S 0 0 A I 3 3 B I 2 C I I 4 4 4 D I 3 3 3 E I I I 6 6 6 6 F I I I I I 7 7 G I I I I I 7 7 H I I I I 5 5 T I I I I I I I 1 3 C G 3 3 D 3 H 2

  32. A 3 E 3 3 B 2 S F 2 T 3 2 0 1 2 3 4 5 6 7 S 0 0 A I 3 3 B I 2 C I I 4 4 4 D I 3 3 3 E I I I 6 6 6 6 F I I I I I 7 7 7 G I I I I I 7 7 7 H I I I I 5 5 T I I I I I I I I 1 3 C G 3 3 D 3 H 2

  33. A 3 E 3 3 B 2 S F 2 T 3 2 0 1 2 3 4 5 6 7 8 S 0 0 A I 3 3 B I 2 C I I 4 4 4 D I 3 3 3 E I I I 6 6 6 6 F I I I I I 7 7 7 G I I I I I 7 7 7 7 H I I I I 5 5 T I I I I I I I I 9 1 3 C G 3 3 D 3 H 2

  34. A 3 E 3 3 B 2 S F 2 T 3 2 0 1 2 3 4 5 6 7 8 9 S 0 0 A I 3 3 B I 2 C I I 4 4 4 D I 3 3 3 E I I I 6 6 6 6 F I I I I I 7 7 7 G I I I I I 7 7 7 7 H I I I I 5 5 T I I I I I I I I 9 8 1 3 C G 3 3 D 3 H 2

  35. A 3 E 3 3 B 2 S F 2 T 3 2 0 1 2 3 4 5 6 7 8 9 S 0 0 A I 3 3 B I 2 C I I 4 4 4 D I 3 3 3 E I I I 6 6 6 6 F I I I I I 7 7 7 G I I I I I 7 7 7 7 H I I I I 5 5 T I I I I I I I I 10 9 1 3 C G 3 3 D 3 H 2

  36. A 3 E 3 3 B 2 S F 2 T 3 2 0 1 2 3 4 5 6 7 8 9 S0 A I 3 3 BI2 C II 4 4 4 D I 3 3 3 E I I I 6 6 6 6 F I I I I I 7 7 7 G I I I I I 7 7 7 7 H I I I I 5 5 T I I I I I I I I 10 9 1 3 C G 3 3 D 3 H 2

  37. A 3 E 3 3 B 2 S F 2 T 3 2 0 1 2 3 4 5 6 7 8 9 S 0 0 A I 3 3 B I 2 C I I 4 4 4 2 D I 3 3 3 E I I I 6 6 6 F I I I I I 7 G I I I I I 7 H I I I I 5 5 T I I I I I I 1 3 C G 3 -3 D 3 H 2

  38. Dijkstra Algorithm • Single source shortest path algorithm • If there is a negative edge, what happens? • Complexity: O(V2)

  39. Dijkstra Algorithm • Improvement on the algorithm • Use priority queue to find get the vertex v with minimum d[v] • Complexity: O(V log V) The details will not be taught in this lesson

  40. Warshall-Floyd • All-pairs shortest path algorithm • Negative edges may be present, but not negative cycle

  41. Warshall-Floyd d[i][j] ← wuvif (i,j) is an edge d[i][j] ← ∞ if (i,j) is not an edge for eachi in V for eachjin V for eachkin V if d[j][k] > d[j][i] + d[i][k] d[j][k] ← d[j][i] + d[i][k]

  42. Warshall-Floyd d[i][j] ← wuvif (i,j) is an edge d[i][j] ← ∞ if (i,j) is not an edge for eachi in V for eachjin V for eachkin V if d[j][k] > d[j][i] + d[i][k] d[j][k] ← d[j][i] + d[i][k] p[k]= i

  43. Warshall-Floyd (30048) d[i][j] ← wuvif (i,j) is an edge d[i][j] ← ∞ if (i,j) is not an edge for eachi in V for eachjin V for eachkin V if d[j][k] > max(d[j][i] , d[i][k]) d[j][k] ← max(d[j][i] , d[i][k])

  44. Warshall-Floyd • Be careful of the positions of i,j and k • Complexity: O(V3)

More Related