Definition. The weight, or length, of a path v 0 , v 1 , v 2 , …, v k in weighted graph
k-1
G = (V, E, W) is W(v i v i+1 ). Path v 0 , v 1 , v 2 , …, v k is the shortest path from
i = 0
v 0 to v k if there is no other path from v 0 to v k with lower weight.
Definition. The distance from vertex x to vertex y (x, y V), denoted as
d(x,y) is the weight of the shortest path from x to y .
The problem: Given x V, we want to find the shortest paths from x to any
other vertex in V in order of increasing distance from x. Consider the following
two cases:
All weights are "1". Therefore, the problem becomes finding a path containing the minimum number of edges. To solve this problem, we can use the breadth-first search algorithm.
If edge weights are different, we can use the Dijkstra's shortest path algorithm.
10.
The shortest-path problem: Dijkstra's algorithm
Extended example to be distributed in class!
To implement Dijkstra's algorithm we need the following data structures:
An integer array, distance , of NumberOfNodes size (assuming that edge weights are integers).
A Node array, path , of NumberOfNodes size.
A Boolean array, included , of NumberOfNodes size.
Given the start node, the initialization of these arrays is the following:
included[start] := true, all other entries in included initialized to false.
0, if node = start
distance[node] := EdgeWeight(start, node)
, if there does not exist a direct edge between
start and node
path[node] := start, if there exists an edge between start and node
Views
Actions
Embeds 0
Report content