Presentation is loading. Please wait.

Presentation is loading. Please wait.

Weighted Graphs & Shortest Paths

Similar presentations


Presentation on theme: "Weighted Graphs & Shortest Paths"— 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 cost updated

13 Dijkstra's Algorithm Finds shortest path to all other vertices
Can terminate early once goal is known Assumption: No negative edges

14 A* A-Star : Dijkstra's algorithm, but include estimate of future cost for every vertex Estimate must never overestimate cost

15 MST Minimum Spanning Tree
Spanning tree with minimal possible total weight

16 Prim's MST Conceptual: Sound familiar? 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?

17 Prim's MST ~ Dijkstra's Conceptual: One big difference…
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…

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

19 Prim's Algorithm Finds a MST Assumption: May be multiple equal cost
Undirected


Download ppt "Weighted Graphs & Shortest Paths"

Similar presentations


Ads by Google