1 / 23

Dijkstra’s Algorithm

Dijkstra’s Algorithm. Text Read Weiss, § 9.3 Dijkstra’s Algorithm Single Source Multiple Destination Shortest Path Algorithm . Requirements. Works with directed and undirected graphs Works with weighted and unweighted graphs Rare type of algorithm 

conan
Download Presentation

Dijkstra’s Algorithm

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’s Algorithm Text • Read Weiss, § 9.3 Dijkstra’s Algorithm • Single Source Multiple Destination Shortest Path Algorithm

  2. Requirements • Works with directed and undirected graphs • Works with weighted and unweighted graphs • Rare type of algorithm  A greedy algorithm that produces an optimal solution

  3. Walk-Through 2 Initialize array 3 F C 5 A 10 7 3 4 8 18 4 B D 9 10 H 9 25 2 3 G E 7

  4. 2 Start with G 3 F C 5 A 10 7 3 4 8 18 4 B D 9 10 H 9 25 2 3 G E 7

  5. 2 Update unselected nodes 3 F C 5 A 10 7 3 4 8 18 4 B D 9 10 H 9 25 2 3 G E 7

  6. 2 Select minimum distance 3 F C 5 A 10 7 3 4 8 18 4 B D 9 10 H 9 25 2 3 G E 7

  7. 2 Update unselected nodes 3 F C 5 A 10 7 3 4 8 18 4 B D 9 10 H 9 25 2 3 G E 7

  8. 2 Select minimum distance 3 F C 5 A 10 7 3 4 8 18 4 B D 9 10 H 9 25 2 3 G E 7

  9. 2 Update unselected nodes 3 F C 5 A 10 7 3 4 8 18 4 B D 9 10 H 9 25 2 3 G E 7

  10. 2 Select minimum distance 3 F C 5 A 10 7 3 4 8 18 4 B D 9 10 H 9 25 2 3 G E 7

  11. 2 Update unselected nodes 3 F C 5 A 10 7 3 4 8 18 4 B D 9 10 H 9 25 2 3 G E 7

  12. 2 Select minimum distance 3 F C 5 A 10 7 3 4 8 18 4 B D 9 10 H 9 25 2 3 G E 7

  13. 2 Update unselected nodes 3 F C 5 A 10 7 3 4 8 18 4 B D 9 10 H 9 25 2 3 G E 7

  14. 2 Select minimum distance 3 F C 5 A 10 7 3 4 8 18 4 B D 9 10 H 9 25 2 3 G E 7

  15. 2 Update unselected nodes 3 F C 5 A 10 7 3 4 8 18 4 B D 9 10 H 9 25 2 3 G E 7

  16. 2 Select minimum distance 3 F C 5 A 10 7 3 4 8 18 4 B D 9 10 H 9 25 2 3 G E 7

  17. 2 Update unselected nodes 3 F C 5 A 10 7 4 8 18 4 B D 9 10 H 9 25 2 3 G E 7

  18. 2 Select minimum distance 3 F C 5 A 10 7 4 8 18 4 B D 9 10 H 9 25 2 3 G E 7 Done

  19. Order of Complexity • Analysis • findMin() takes O(V) time • outer loop iterates (V-1) times  O(V2) time • Optimal for dense graphs, i.e., |E| = O(V2) • Suboptimal for sparse graphs, i.e., |E| = O(V)

  20. Order of Complexity • If the graph is sparse, i.e., |E| = O(V) • maintain distances in a priority queue • insert new (shorter) distance produced by line 10 of Figure 9.32  O(|E| log |V|) complexity

  21. Negative Edge Weights • Read § 9.3.3 • Dijkstra’s algorithm as shown in Figure 9.32 does not work! Why?

  22. Acyclic Graphs • Read § 9.3.4 • Combine topological sort with Dijkstra’s algorithm

  23. All-Pairs Shortest Paths • One option: run Dijktra’s algorithm |V| times  O(V3) time • A more efficient O(V3) time algorithm is discussed in Chapter 10

More Related