Assignment5 (Written) Solution
Assignment5 (Written) Solution
let Q be a priority queue that contains all of the vertices of G using the D labels as keys.
while Q do
u Q.removeMinElement()
ModifiedShortestPath(G,v)
is
like
Dijkstras
shortest
path,
but
stops
when
reaches
the
first
vertex
at
distance
larger
than
30.
The
analysis
is
like
that
one,
worst
case
O(m
log
n);
or
more
precisely,
if
n1
is
the
number
of
vertices
at
distance
<=30
from
v,
and
m1
is
the
total
number
of
edges
such
that
one
of
its
ends
is
at
distance
<=30
from
v,
then
this
runs
in
O(n+
m1
log
n1).
If
running
once
per
vertex
the
running
time
is
O(nm
log
n).
2.2
(20
points)
Apply
the
DFS
algorithm
to
the
following
graph
starting
from
vertex
1.
Assume
that
the
incident
edges
are
stored,
for
each
vertex,
in
increasing
order
of
their
weight.
List
the
vertices
in
order
of
visit.
Clearly
show
the
labels
that
will
be
assigned
to
each
edge
(Discovery
or
Back)
Visited
order
1
0
7
6
5
2
8
3
4
discover/back
-
(1,0)
(0,7)
(7,1)
(7,6)
(6,5)
(5,2)
(2,1)
(2,8)
(8,6),
(8,7)
(2,3)
(3,5)
(3,4)
(4,5)
Algorithm DFS(G, v)
setLabel(v, VISITED)
for all e G.incidentEdges(v) // Edges with
if getLabel(e) = UNEXPLORED
w opposite(v,e)
if getLabel(w) = UNEXPLORED
setLabel(e, DISCOVERY)
DFS(G, w)
else
setLabel(e, BACK)