























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This course object is to design and analysis of modern algorithms, different variants, accuracy, efficiency, comparing efficiencies, advance designing techniques. In this course algorithm will be analyse using real world examples. This lecture includes: Dijkstra, Algorithm, Graph, Shortest, Path, Approach, Vertices, Edges, Relaxation, Analysis, Example
Typology: Slides
1 / 31
This page cannot be seen from the preview
Don't miss anything!
























-^ Given a graph G = (V, E) with a source vertex s,weight function w, edges are non-negative, i.e.,w(u, v)
(u, v)^
-^ The graph is directed, i.e., if (u, v)
^ E then (v, u)
may or may not be in E.• The objective is to find shortest path from s to everyvertex u
Input Given graph G(V, E) with source s, weights wAssumption•^ Edges non-negative, w(u, v)
≥^ 0,^ ^
(u, v)^
E
-^ Directed, if (u, v)
^ E then (v, u) may be in E Objective: Find shortest paths from s to every u
^ V
Approach•^ Maintain a set S of vertices whose final shortest-pathweights from s have been determined•^ Repeatedly select, u
^ V – S with minimum shortest
-^ Consider edge e = (u, z)such that• u is vertex most recentlyadded to the cloud S• z is not in the cloud•^ Relaxation of edge eupdates distance d(z) asd(z) =min {d(z), d(u) + weight(e)}
d ( z )^ ^75 d ( u )^ ^50
z
s^
u
d ( z )^ ^60 d ( u )^ ^50
z
s^
V- S e S eu S V - S
(^0) s^5
∞^
∞ 10
1 (^32) (^94 )
6 t^
x y^
z
∞
For each vertex
v^ ^ V(G) d [ v ]^ ←
π[ v ]^ ←
Considering
s^ as root node d [ s ]^
z 0
s^5 t
∞ 10
1 2 3
(^94 )
6 t^
x y^
z (^100) 5
∞
z
s^ is extracted form queue S^ ^ S^
{s} Adj [ s ] =^
t, y d [ t ] >^ d [ s ] +^ w
( s, t ) (∞^ > 0 + 10)^ d [ t ]^ ←
d [ s ] +^ w
( s, t ) 0 + 10 = 10 π[ t ]^ ←^ s d [ y ] >^ d [ s ] +
w ( s, y ) (∞^ > 0 + 5)^ d [ y ]^ ←
d [ s ] +^ w
( s, y ) 0 + 5 = 5 π[ y ]^ ←^ s
10^5
(^10) s^5
1 2 3
(^94 )
6 t^
x y^
z 0
8
13 7 5
z^ is extracted form queue S^ ^ S^
{z} Adj [ z ] =
s, x d [ s ] >^ d [ z ] +
w ( s, z ) But (0 < 7 + 7) d [ x ] >^ d [
z ] +^ w ( z, x
) (14 > 7 + 6)^ d [ x ]^ ←
d [ z ] +^ w
( z, x ) 7 + 6 = 13 π[ x ]^ ←^ z
(^10) s^5
1 2 3
(^94 )
6 t^
x y^
z 0
8
9 7 5
t^ is extracted form queue S^ ^ S^
{t} Adj [ t ] =^
x, y d [ x ] >^ d [ t ] +^ w
( t, x ) (13 > 8 + 1)^ d [ x ]^ ←
d [ t ] +^ w
( t, x ) 8 + 1 = 9 π[ x ]^ ←^ t d [ y ] >^ d [ t ] +
w ( t, y ) But (5 < 8 + 3)
Cost depends on implementation of min-priority queueCase 1:Vertices being numbered 1 to
|V|
-^ INSERT, DECREASE-KEY operations takes
O(1)
-^ EXTRACT-MIN operation takes
O(V)^ time
-^ Sub cost is O(V
-^ Total number of edges in all adjacency list is |E| •^ Total Running time =
(^2) O (V+ E)
(^2) = O(V )
Case 2:Graph is sufficiently spare, e.g.,
2 /lgV)
Implement min-priority queue with binary min heapVertices being numbered 1 to
-^ Each EXTRACT-MIN operation takes
O(lgV)
-^ There |V| operations, time to build min heap O(V)•^ Sub cost is O(V lgV) •^ Each DECREASE-KEY operation takes time O(lgV),and there are |E| such operation. •^ Sub cost is O(E lgV)^ Hence Total Running time =
lgV =^
E^ lgV
4.^ while
do^ u^ ←
^ {u}
7.^
for^ each vertex v
^ Adj[u]
do^ RELAX(u, v, w) Running time: O(V
Note:Running time depends on Impl. Of min-priority (Q)
(V)
O(V) build min-heap
O(V)
O(V) O(E)
4.^ while
do^ u^ ←
^ {u}
7.^
for^ each vertex v
^ Adj[u]
do^ RELAX(u, v, w)
9.^ Running time: O(VlgV + ElgV) = O(ElgV)
(V)
O(V) build min-heap
Executed O(V) times
O(lgV) O(E) times O(lgV)
Dijkstra’s algorithm, runs on a weighted, directedgraph^
with non-negative weight function
w^ and source
s,^ terminates with
d[u] =
δ(s, u)
for all vertices
Proof•^ We use the following loop invariant:– At start of each iteration of the
while^
loop of
lines 4-8,
d [ v ] =^
δ ( s ,^ v ) for each vertex
-^ It suffices to show for each vertex
, we have
d [ u ] =^ δ
( s ,^ u ) at the time when
u^ is added to set
-^ Once we show that
d [ u ] =^
δ ( s ,^ u ), we rely on the
upper-bound property to show that the equalityholds at all times thereafter.Initialization
-^ Initially,
S^ = Ø, and so the invariant is trivially true
-^ We wish to show that in each iteration,^ d
[ u ] =^ δ (
s ,^ u ), for the vertex added to set