1 / 18

Weighted Graphs & Shortest Paths

Weighted Graphs & Shortest Paths. Weighted Graphs. Edges have an associated weight or cost. BFS?. BFS only gives shortest path in terms of edge count , not edge weight. Dijkstra's Shortest Path Algorithm. Conceptual: V = all vertices T = included vertices

devin
Download Presentation

Weighted Graphs & Shortest Paths

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. Weighted Graphs& Shortest Paths

  2. Weighted Graphs • Edges have an associated weight or cost

  3. BFS? • BFS only gives shortest path in terms of edge count, not edge weight

  4. Dijkstra's Shortest Path Algorithm • Conceptual: • V = all vertices • T = included vertices • Pick starting vertex, include in T • Pick element not in T with minimal cost to reach from T • Move to T • Update costs of remaining vertices

  5. Dijkstra's • Find paths from u to all others:

  6. Dijkstra's • Find paths from u to all others:

  7. Dijkstra's • Find paths from u to all others:

  8. Dijkstra's • Find paths from u to all others:

  9. Dijkstra's • Find paths from u to all others:

  10. Dijkstra's • Find paths from u to all others:

  11. Dijkstra's • Find paths from u to all others:

  12. Details • Implementation • Known once visited • Cost starts at  • Update all neighbors at each visit • Path marked when costupdated

  13. Dijkstra's Algorithm • Finds shortest path to all other vertices • Can terminate early once goal is known • Assumption: • No negative edges • Big O – for the curious • O(V2) with table • V times do linear search for next vertex to visit • O((E + V)logV) with priority queue (binary heap) • O(E + VlogV) possible with fibonacci heap

  14. MST • Minimum Spanning Tree • Spanning tree with minimal possible total weight

  15. Prim's MST • Conceptual: • V = all vertices • T = included vertices • Pick starting vertex, include in T • Pick element not in T with minimal cost to reach from T • Move to T • Update costs of remaining vertices Sound familiar?

  16. Prim's MST ~ Dijkstra's • Conceptual: • V = all vertices • T = included vertices • Pick starting vertex, include in T • Pick element not in T with minimal cost to reach from T • Move to T • Update costs of remaining vertices : cost = just current edge One big difference…

  17. Prim's Implementation • Same as Dijkstra's but… • Cost of vertex = min( all known edges to it )

  18. Prim's Algorithm • Finds a MST • May be multiple equal cost • Assumption: • Undirected • Big O – for the curious • O(V2) with table • V times do linear search for next vertex to visit • O((E + V)logV) with priority queue (binary heap) • O(E + VlogV) possible with fibonacci heap

More Related