I’m trying to understand the main concepts of graph theory and the algorithms within it. Most algorithms seem to contain a “Relaxation Condition” I’m unsure about what this is.
Could some one explain it to me please.
An example of this is dijkstras algorithm, here is the pseudo-code.
1 function Dijkstra(Graph, source):
2 for each vertex v in Graph: // Initializations
3 dist[v] := infinity // Unknown distance function from source to v
4 previous[v] := undefined // Previous node in optimal path from source
5 dist[source] := 0 // Distance from source to source
6 Q := the set of all nodes in Graph
// All nodes in the graph are unoptimized - thus are in Q
7 while Q is not empty: // The main loop
8 u := vertex in Q with smallest dist[]
9 if dist[u] = infinity:
10 break // all remaining vertices are inaccessible from source
11 remove u from Q
12 for each neighbor v of u: // where v has not yet been removed from Q.
13 alt := dist[u] + dist_between(u, v)
14 if alt < dist[v]: // Relax (u,v,a)
15 dist[v] := alt
16 previous[v] := u
17 return dist[]
Thanks
Relaxation step:
uandvThe relaxation step basically is asking this:
vwith some path of distancedist[v]. Could I improve on this by going tovthroughuinstead? (where the distance of the latter would bedist[u] + weight(u, v))Graphically:
You know some path
s~>vwhich has distancedist[v], and you know some paths~>uwhich has distancedist[u]. Ifdist[u] + weight(u, v) < dist[v], then the paths~>u->vis shorter thans~>v, so you’d better use that one!(I write
a~>bto mean a path of any length fromatob, whilea->bI mean a direct single edge fromatob).You may also want to check this lecture: http://ocw.mit.edu/OcwWeb/Electrical-Engineering-and-Computer-Science/6-046JFall-2005/VideoLectures/detail/embed17.htm