Single Source Shortest Path - PowerPoint PPT Presentation

About This Presentation
Title:

Single Source Shortest Path

Description:

Single Source Shortest Path. Given a weighted, directed graph G = (V,E), with ... Repeatedly decreases an upper bound on the actual shortest path weight of each ... – PowerPoint PPT presentation

Number of Views:61
Avg rating:3.0/5.0
Slides: 20
Provided by: somc7
Category:
Tags: algo | path | shortest | single | source

less

Transcript and Presenter's Notes

Title: Single Source Shortest Path


1
Single Source Shortest Path
Given a weighted, directed graph G (V,E), with
weight function w E -gt R .
Weight of path p
Shortest path weight from u to v
Shortest path from u to v is defined as any path
p with weight
2
Single source shortest path problem find a
shortest path from a given source vertex s in V
to every vertex v in V
  • Variants
  • Single destination shortest path
  • Single pair shortest path
  • All pairs shortest path

Shortest path weight is not well defined if there
is a negative weight cycle reachable from s.
3
Relaxation
Repeatedly decreases an upper bound on the actual
shortest path weight of each vertex until the
upper bound equals the shortest path weight.
Optimal structure of a shortest path
A shortest path between two vertices contains
other shortest path within it.
Lemma 25.1 subpaths of shortest path are
shortest path (proof by contradiction)
Lemma 25.2 suppose a shortest path p can be
decomposed then
Lemma 25.3 all edges
4
Relaxation (cont)
Let dv be an upper bound on weight shortest
path s to v , shortest path estimate. Relaxation
is a testing whether we can improve the shortest
path to v found so far by going through u, if so
updating dv and piv
5
Relaxation (cont)
  • Initialize-single-source(G,s)
  • 1 for each v in VG
  • do dv inf
  • piv NIL
  • ds 0

6
Relaxation (cont)
  • Relax(u,v,w)
  • 1 if dv gt du w(u,v)
  • then dv du w(u,v)
  • piv u

7
(No Transcript)
8
Properties of relaxation
Lemma 25.4 After execute Relax(u,v,w)
Lemma 25.5 After initialize,
This invariant is maintained over any sequence of
relaxation steps. Once dv achieves its lower
bound, it never changes. (proof by contradiction)
9
Properties of relaxation (cont)
Corollary 25.6 if no path s to v then after
initialize
and this equality is maintained as an invariant.
Lemma 25.7 let
be the shortest path. Suppose G is initialize
and then a sequence of relaxation steps that
includes Relax(u,v,w) is executed. If
at any time prior to the call, then
at all times after the call.
10
Dijkstras algorithm
S a set of vertices whose final shortest path
weights from the source have already been
determined.
Repeatedly selects
with minimum
shortest path estimate, inserts u into S and
relax all edges leaving u.
Q priority queue contains all vertices in V-S
keyed by their d values.
11
  • Dijkstra(G,w,s)
  • 1 initialize-single-source(G,s)
  • 2 s 0
  • 3 Q VG
  • 4 while Q ! 0
  • do u Extract-min(Q)
  • S S u u
  • for each vertex u in Adju
  • do Relax(u,v,w)

12
(No Transcript)
13
(No Transcript)
14
(No Transcript)
15
(No Transcript)
16
(No Transcript)
17
(No Transcript)
18
  • Dijkstra(G,w,s)
  • 1 initialize-single-source(G,s)
  • 2 s 0
  • 3 Q VG
  • 4 while Q ! 0
  • do u Extract-min(Q)
  • S S u u
  • for each vertex u in Adju
  • do Relax(u,v,w)

QV-S as linear array Each O(V) so
O(V2) Loop E iterations Total O(V2E) O(V2)
O(V)
19
Running time of Dijkstra
Can achieve a running time of O(V lg V E) by
implementing the priority queue Q with a
Fibonacci heap. The amortized cost of each
Extract-min is O(lg V), V times. The assignment
in Relax is accomplished by the call
Decrease-key(Q,v,duw(u,v)), which takes time
amortized time O(1), E times.
Write a Comment
User Comments (0)
About PowerShow.com