This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: —
hmgto Unneuts mSt 10m» Engineering Shortest Paths in
Directed Graphs Jon Turner Computer Science & Engineering
Washington University www.ar1.wustl.edu/~jst —
Engineering Shortest Paths in Graphs last/e ﬁs‘ﬂ
éﬁtta ®t%3% E Washington University in St. Louis 3 $4 gag 3%,_4>®/ shortest path shortest path tree ILet G = (V,E) be a directed graphs and let length
be a realvalued function on E >>the length ofa path is the sum of the lengths of its edges
>>a shortest path is a path of minimum length >>edge lengths can be negative, so path lengths can be also
obut no shortest path in presence of negative length cycles $Msh1ngton UnwersuymStlouis Engineering Shortest Path Problems nThe shortest path problem has several versions >>sing/e pair prob/em: given a source vertex 5 and a sink
vertex t, find a shortest path from s to t >>sing/e source prob/em: given a source vertex 5, find a
shortest path from s to every other vertex in G >>sing/e sink prob/em: given a sink vertex t, find a shortest
path to t from every other vertex in G >>a/l pairs prob/em: find a shortest path between every pair
of vertices nThe single source and single sink problems are
essentially the same I Most solutions to the single pair problem
effectively solve a single source problem —
Engineering E Washington University in St. Louis Shortest Path Trees I Theorem 7.1. Let G be digraph with path from s to t.
There is a shortest path from s to t if and only if no
path from s to t contains a negative cycle. If there is a
shortest path from s to t, there is one that is simple. Proof. If some st path includes a negative cycle, we can produce
an arbitrarily short path by traversing the cycle enough times. If there is no negative cycle then we can make any st path simple
without increasing its length by deleting cycles. I .A shortest path tree for vertex 5 is a directed spanning
tree with root 5 each of whose paths is a shortest path.  Theorem 7.2. G contains shortest paths from s to every
other vertex if and only if it contains a shortest path
tree with root 5. Proof deferred. ‘vWashmgton Unwersuy mStlQUb Engineering I Let T be any spanning tree of G with root 5
>> let distance(v) to be length of the path from s to v in T  Theorem 7.3. T is a shortest path tree if and only if,
distance(w)5distance(v)+length(v,w), for every edge
[v,w] in G Proof. If T is shortest path tree in which distance(w)> distance(v)
+length(v,w) for some edge [v,w], then there is a shorter path than the one in T Conversely, suppose distance(w)sdistance(v)+length(v,w) for
every edge [v,w] and let p be any path from s to any vertex X. oshow by induction on number of edges in p that distance(x)
slength(p); the basis, p=1 is immediate. ofor inductive step, assume distance(x’)slength(p’) for all vertices X' and paths p' with p’=k; let p be a path from s to some vertex
X of length k+1, let q=p—[X] and let y be last vertex on q o by induction, distance(y)slength(q), so distance(x)sdistance(y)+
/ength(y,x)Slength(q)+length(y,x)=/ength(p) I ~3 Washmgton UnlverSItymStlouls Engineering Review Questions 1. Draw a directed graph with at least 8 vertices and 12 edges in which
every vertex can be reached from every other vertex. Assign a positive
length to each of the edges. Label each vertex with a letter. Find a
shortest path tree in the graph from vertex c. Label each vertex with its
distance in the tree from c. . Select three edges from your example in the previous question that are
not in your shortest path tree. Show that all three edges satisfy the
condition in Theorem 7.3. . Find a directed spanning tree in your graph from question 1 that is not a
shortest path tree. Label each vertex with its distance in the tree from the source node. Find at least one edge in the graph that violates the
condition in Theorem 7.3. ~3 Washmgton UnwersuymStlouls Engineering The Labeling Method l Labeling method finds an SPT by repeatedly applying
Theorem 7.3 >> uses two mappings: dist(v) is length of shortest path so far
from s to v, p(v) is the parent of v in the current partial SPT >> initially, p(s)=null, dist(s)=0 and p(v)=null, dist(v)=oc for v¢s
>> Labeling Step: select edge [v,w] for which dist(w)>dist(v)+
Iength(v,w); let p(w)=v, dist(w)=dist(v)+/ength(v,w)
.Lemma 7.1. The labeling method maintains invariant
that if dist(v) is finite, there is a path from s to v of
length dist(v) Proof. By induction on the number of labeling steps I ILemma 7.2. If p is any path from s to any vertex v,
then dist(v)slength(p) when the labeling method halts Proof. By induction on number of edges in p I $Msh1ngton UnwersuymStlouls Engineering .Theorem 7.4. When labeling method halts, dist(v) is
length of a shortest path from s to v if v is reachable from s; dist(v)=oo otherwise. If there is a negative cycle
reachable from s, the method never halts. Proof. Follows from Theorem 7.1 and Lemmas 7.1, 7.2 I ILemma 7.3. Labeling method maintains the invariant
that if p(v)¢null, dist(v)zdist(p(v))+/ength(p(v),v) with equality when the method halts.
Proof. By induction on number of labeling steps I ILemma 7.4. At each step of labeling method, either the
edges [p(v),v] with p(v)¢null form a tree rooted at s
spanning all vertices v with dist(v)<oc, or there is a
cycle of parent pointers. Proof. A vertex V¢S has p(v)¢null iff dist(v)<oo. If dist(v)<oc and p
(v)¢null then dist(p(v))<oc. Thus, if we follow parent pointers from
any vertex v, we either encounter s or repeat a vertex. l 8 ~. Washmgton Unwersuy 1n Stlouls Engineering .Lemma 7.5. If labeling method creates a cycle of
parent pointers, the corresponding cycle of G is
negaﬁve Proof. Suppose that a labeling step on edge [X,y] creates a cycle of parent pointers; just before the step, pk(x)=y for some k; by
Lemma 7.3, dist(p"(x))zdist(p’+1(x))+/ength(p’+1(x),pi(x)) for
Osi<k; summing these inequalities gives Ego/isrw’o» 2 2,; disr(p"(x>> + Efgo‘lengrmpi“ (x), pi<x>> adding the inequality dist(y)>dist(x)+/ength(x,y) and noting that
y=pk(x) and X=p0(x) gives 2f=ndi.€t(p"(x)) > 2:0diivt(pi(x)) + EglenngpM (x), [)i(x)) + length(x,y) 0 > EglengtMp'”(x),p'(x)) + length(x,y) hence the cycle of parent pointers created by the labeling step
corresponds to a negative cycle of G I $Msh1ngton UanCFSIthStlDUIS Engineering I Theorem 7.5. When the labeling method halts, the
parent pointers define a shortestpath tree for the
subgraph of G reachable from s Proof. Immediate from Theorem 7.4 and Lemmas 7.3, 7.4, 7.5 l  Labeling method can take 9(2") time if order in which
edges are chosen is poor >> for example, labeling method can take 9(2") steps on the
graph Gk defined below 61 1 In ~3 Washmgton UnwersuymStlouls Engineering Scanning and Labeling IScanning and labeling method is a special case of the
labeling method, where we select all “eligible” edges
leaving a particular vertex as a group >> each vertex can be in one of three states: unlabeled, labeled, or
scanned; initially sis labeled and all others are unlabeled >> Scanning Step. Select a labeled vertex v and convert v to the
scanned state; for all [v,w] with dist(w)>dist(v)+ length(v,w),
replace p(w) by v and dist(w) by dist(v)+ length(v,w)
convert w to the labeled state >> correctness follows directly from correctness of labeling method
I Different vertex selection rules yield different variants  For acyclic graphs select vertices to be scanned in
topological order >> no vertex is scanned more than once giving 0(m) running time11 II ~3 Washmgton UnlverSItymStlouls Engineering Shortest First Scanning I In shortest first scanning, select vertex v for which dist
(v) is minimum
>> if every edge has non—negative length, each vertex will be
scanned at most once.
I Theorem 7.6. If every edge has nonnegative length
and scanning is shortest first, then after vertex v is
scanned, dist(v) is length of shortest path from s to v. Proof. Just before a vertex v is scanned, dist(v)sdist(w) for any
labeled vertex w In addition, dist(v)sdist(w) for any vertex w that becomes labeled
during or after the scanning of v Consequently, the vertices are scanned in nondecreasing order of
distance from s and once a vertex is scanned it cannot become
labeled l 1’) ‘vWashmgton Unlversm mStlQUb Engineering Dijkstra’s Algorithm .Similar to Prim's MST algorithm; same running time
procedure dijkstra(digraph G=(V,E), vertex 3,
mapping p: vertex—>vertex);
vertex u,v; heap S;
for uEV => dist(v):=oc; p(u):=nu; rof;
dist(s):=0; insert(s,0,S);
do S¢{} =>
u:=deetemin(8);
for {u,v}Eout(u) =>
if dist(v)>dist(u)+/ength(u,v) =>
p(v):=u; dist(v):=dist(u)+/ength(u,v);
if v6.58 => insert(v,dist(v),S);
 vES => changekey(v,dist(v),8);
fi; fi; I? $Msh1ngton UanCFSIthSthUIS Engineering WorstCase for Dijkstra IWorstcase when number of changekeys is 9(m)
lEdge [v,,vj] with cost(v,,11)=2(j—i)—1 for all i<j
lAfter step k the “current tree” includes path
v1,v2,...,vk and direct edge from vk to V] with j>k
lNumber of changekeys is 1+2+...+n—1 (Q(nz))
lAny subgraph with all [v,,v,+1] edges requires
changekey for all edges except those from v1 I/I \X/ashington University in St. Louis Exercises . The figure below shows an intermediate
state in the execution of the labeling algorithm for shortest paths starting at
vertex a. The heavy edges are the tree edges defined by parent pointers in the
implementation. The distance values are
shown next to the nodes in the diagram. Show the state of the algorithm after edges
(c,g), (g,b), (k,h), (k,f) have been selected fMtheir “heads” updated. —
Engineering 2. Let G be a digraph in which edges have “capacities”. The bottleneck capacity of a path
in G is the minimum edge capacity on the
path. A best bottleneck path tree is a spanning
tree of G in which each path has the largest
possible bottleneck capacity. Let T be a spanning tree of G with roots and
let bcap(u) be the bottleneck capacity of the
path from s to u in T. Show that if Tis a best
bottleneck path tree, then bcap(v)2min{bcap
(u), cap(u,v)}, for all edges (u,v) in G. If bcap(v)<min{bcap(u),cap(u,v)} for some
edge (u,v) then there is a path to v with a
larger bottleneck capacity than the tree path,
implying that T is not a best bottleneck path
tree. Therefore, if T is a best bottleneck path
tree then bcap(v)a min{bcap(u),cap(u,v)}, for
all edges (u,v) in G. Show that if there is a nontree path p from s
to some vertex x, that has bottleneck capacity
larger than bcap(x), then there must be some
edge (u,v) for which bcap(v)<min{bcap(u),cap (u,v)} I: —
Engineering Washington University in St. Louis Assume that D is a Shortest Path sat/Sfy/ng 3. Consider a version of the shortest path problem the condition and that path p has k edges.
If k=1, p consists of the single edge (s,X)
and has bottleneck capacity equal to cap
(s,x)=min{bcap(s),cap(s,x)}, and since p
is assumed to have larger bottleneck
capacity than the tree path to x, it follows that bcap(x) <min{bcap(s),cap(s,x)}. If k>1, let (w,x) be the last edge on p and
note that since p is the shortest nontree
path with larger bottleneck capacity than
the corresponding tree path, the tree path
from s to w is a best bottleneck path.
Consequently, the bottleneck capacity of p
is at most min{bcap(w),cap(w,x)}. Since p
has larger bottleneck capacity than the
tree path to x, this means that bcap(x) <min{bcap(w),cap(w,x)}. with positive edge lengths and multiplicative
costs. In this version, the length of a path is the
product of the edge lengths, rather than the
sum. Explain how shortest path algorithms can
be modified to handle multiplicative costs. What
is the implication of having positive edge costs
that are less than 1? One approach is to replace the original costs by
their logarithms and then use a standard
shortest path algorithm on the graph with the
transformed costs. The resulting distances must then be transformed back to give the
multiplicative distances. Since the log of a product equals the sum of the logs, this yields
the shortest multiplicative paths. Alternatively, one can modify the original
algorithms to replace expressions of the form
dist(u) + length(u,v) with dist(u) * length(u,v)
in the shortest path algorithm. The correctness
of this follows from the logarithm
transformation. Positive edge costs less than 1 reduce path
lengths and have the same effect as negative
edge lengths in the standard problem. If such
edges are present, Dijkstra’s algorithm cannot be used. 16 IK E \X/ashington University in St. Louis . The figure below shows an intermediate state in the
execution of Dijkstra’s algorithm. The bold edges in the graph are the edges defined by
the numbers next to the vertice the parent pointers, and
s are the current distance values. Fill in the blanks (as appropriate) in the
arrays that implement the d—heap (assume d=2 and that
vertices b, c, d and h have not yet been “scanned”). 123456789101112 d 17 c II n 17 c d L’ I‘ V II i Ix I
My 4 7 3 9
I" 2 3 1 4 Show how the heap contents changes after the next iteration: 12 3 4 5 o 7 s 9101 ii lrlflvlhl I I l II 12
 al't'ilcfglliilil 46 5 9
13 2 4 —
Engineering 1’7 ...
View
Full Document
 Spring '12
 JonTurner

Click to edit the document details