Discovering Shortest Path Algorithms in Graph Theory

spooky shortest paths n.w
1 / 102
Embed
Share

Delve into the world of graph theory and uncover the intricacies of finding the shortest path algorithms using Dijkstra's algorithm. Explore the concepts, techniques, and practical applications of determining the most efficient paths between nodes in a graph network.

  • Graph Theory
  • Dijkstras Algorithm
  • Shortest Path
  • Algorithms
  • Practical Applications

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. SPOOKY SHORTEST PATHS David Kauchak CS 140 Fall 2024

  2. Admin Assignment 8 Group 8

  3. Prims

  4. MST Practice

  5. Solution Sum = 8 + 8 + 9 + 9 + 11 + 11 + 12 + 14 = 82

  6. Shortest paths What is the shortest path from a to d? B D A C E

  7. Shortest paths How can we find this? B D A C E

  8. Shortest paths BFS B D A C E

  9. Shortest paths What is the shortest path from a to d? 2 B D 3 3 2 1 A 1 C E 4

  10. Shortest paths What is the shortest path from a to d? 2 B D 3 3 2 1 A 1 C E 4

  11. Shortest path algorithms?

  12. Dijkstras algorithm What is dist? What is prev? How does it work? What is the run-time? How do we get the shortest path?

  13. Dijkstras algorithm

  14. Dijkstras algorithm prev keeps track of the shortest path

  15. Dijkstras algorithm

  16. Dijkstras algorithm

  17. Dijkstras algorithm

  18. 3 B D 3 1 2 1 A 1 C E 4

  19. 3 B D 3 1 2 1 A 1 C E 4

  20. Heap A 0 B C D E 3 B D 3 0 1 2 1 A 1 C E 4

  21. Heap B C D E 3 B D 3 0 1 2 1 A 1 C E 4

  22. Heap B C D E 3 B D 3 0 1 2 1 A 1 C E 4

  23. Heap C 1 B D E 3 B D 3 0 1 2 1 A 1 1 C E 4

  24. Heap C 1 B D E 3 B D 3 0 1 2 1 A 1 1 C E 4

  25. Heap C 1 B 3 D E 3 3 B D 3 0 1 2 1 A 1 1 C E 4

  26. Heap C 1 B 3 D E 3 3 B D 3 0 1 2 1 A 1 1 C E 4

  27. Heap B 3 D E 3 3 B D 3 0 1 2 1 A 1 1 C E 4

  28. Heap B 3 D E 3 3 B D 3 0 1 2 1 A 1 1 C E 4

  29. Heap B 3 D E 3 3 B D 3 0 1 2 1 A 1 1 C E 4

  30. Heap B 2 D E 2 3 B D 3 0 1 2 1 A 1 1 C E 4

  31. Heap B 2 D E 2 3 B D 3 0 1 2 1 A 1 1 C E 4

  32. Heap B 2 E 5 D 2 3 B D 3 0 1 2 1 A 1 1 5 C E 4

  33. Heap E 3 D 5 5 2 3 B D 3 0 1 2 1 A 1 1 3 C E 4

  34. Heap D 5 5 2 3 B D 3 0 1 2 1 A 1 1 3 C E 4

  35. Heap 5 2 3 B D 3 0 1 2 1 A 1 1 3 C E 4

  36. Heap 5 2 3 Prev A: null B: C C: A D: B E: B B D 3 0 1 2 1 A 1 1 3 C E 4

  37. Heap How do we get the actual paths? 5 2 3 Prev A: null B: C C: A D: B E: B B D 3 0 1 2 1 A 1 1 3 C E 4

  38. Heap 5 2 3 Prev A: null B: C C: A D: B E: B B D 0 1 1 A 1 1 3 C E

  39. Is Dijkstras algorithm correct? Invariant: For every vertex removed from the heap, dist[v] is the actual shortest distance from s to v proof?

  40. Is Dijkstras algorithm correct? Invariant: For every vertex removed from the heap, dist[v] is the actual shortest distance from s to v The only time a vertex gets visited is when the distance from s to that vertex is smaller than the distance to any remaining vertex Therefore, there cannot be any other path that hasn t been visited already that would result in a shorter path

  41. Running time?

  42. Running time? (|V|) 1 call to MakeHeap |V| calls to Extract-Min |E| calls to Decrease-Key

  43. Running time? Depends on the heap implementation 1 MakeHeap |V| ExtractMin |E| DecreaseKey Total Array O(|V|) O(|V|2) O(|V|2) O(|E|) Bin heap O(|V|) O(|V| log |V|) O((|V|+|E|) log |V|) O(|E| log |V|) O(|E| log |V|) Fib heap O(|V|) O(|V| log |V|) O(|V| log |V| + |E|) O(|E|)

  44. Dijkstras vs Prims

  45. What about Dijkstras on? 1 B D 1 5 A 10 -10 E C

  46. What about Dijkstras on? Dijkstra s algorithm only works for positive edge weights 1 B D 1 5 A 10 E C

  47. Is Dijkstras algorithm correct? Invariant: For every vertex removed from the heap, dist[v] is the actual shortest distance from s to v The only time a vertex gets visited is when the distance from s to that vertex is smaller than the distance to any remaining vertex Therefore, there cannot be any other path that hasn t been visited already that would result in a shorter path We relied on having positive edge weights for correctness!

  48. Bounding the distance Another invariant: For each vertex v, dist[v] is an upper bound on the actual shortest distance Is this a valid invariant?

More Related Content