Download presentation
Presentation is loading. Please wait.
1
Shortest paths & Weighted graphs
Based on Data Structures, Algorithms & Software Principles in C T. A. Standish, A-W (Pearson), 1998
2
Terms Weighted graph Weighted adjacency matrix
Numerical values attached to edges are called weights Represent: costs, distances, times, etc. Weighted adjacency matrix A row/col intersection (edge exists from A-> B) contains the weight of the edge (vs a 1/0 of a non-weighted matrix) A row/col intersection for a non-existent edge contains a value ≡ ∞
3
Usage Distance on a map (GPS implications) Cost to fly a plane
Computer network shortest # hops or delay time Social media: degree of separation Arbitrage (currency exchange) convert (USD->EUR->CNY->USD) 1000 US$ to ₠ 810 (*.81) ₠ 810 to CNY (*7.73, 4/22/'18) CNY back to US$ (rate=.16) Profit of 1.80 USD (known as) in 1 msec (find a negative cycle)
4
Weighted Di-Graph & it's Adj1 Shortest path A→D, is: ACEFD
To 3 B A B C D E F ∞ 9 3 5 4 7 8 1 6 9 8 4 D 5 C 6 From 7 F 1 E
5
Finding the shortest path
Easy if all weights are equal (simple BFS) Dijkstra's algorithm - shortest path for ONE pair See pg 426 for example and proof of correctness O(V2), but O(V+ E* log V) if a min-priority queue is used Floyd-Warshall algorithm - shortest path for ALL pairs O(V3) See
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.