1
Graph Algorithms לע םימת ירוגלא םיפ רג
2
Shortest-Path Problems
! A weighted graph G=(V,E) is a
graph in which each edge e∈E has a weight (cost) w(e) associated with it.
! Path cost: the cost of a path
p=〈v0,…,vk〉 is the sum of the weights
- f its edges:
! Shortest path problems:
– Single source – All pairs
( ) ( )
∑
= −
=
k i i i
v v w p w
1 1,
3
Shortest-Path Problems
! Single-source shortest paths
problem: given a directed graph G=(V,E), in which each edge has non- negative cost, and a source s∈V, compute the cheapest path from s to every other vertex in V.
! All-pairs shortest paths problem:
given a directed graph G=(V,E), in which each edge has non-negative cost, compute for every ordered pair of vertices (u,v) the cheapest path from u to v.
4
Dijkstra’s Algorithm
! Maintain a set of vertices S whose
shortest path from the source has already been discovered (initially S contains only the source vertex).
! At each iteration add to S a vertex
from V-S with the minimum shortest- path estimate
! Update shortest-path estimates for V-S
1 2 10 5 2 3 4 6 9 7