CSE 331 Spring 2008, Section 1
Homework 9 Solutions
1.
Consider the following graph:
This is a directed, acyclic graph containing a single negativeweighted edge.
If we run Dijkstra's
algorithm on this graph, we will get the following series of tables.
Step
Known
Distance
Parent
A
B
C
A
B
C
A
B
C
init
F
F
F
0
∞
∞
/
/
/
A
T
F
F
0
1
2
/
A
A
B
T
T
F
0
1
2
/
A
A
C
T
T
T
0
1
2
/
A
A
As we can see, Dijkstra's algorithm has us go from A to B directly, following an edge with a
weight of 1.
Once it has found this path and removed B from the priority queue, Dijkstra's
algorithm assumes that it is the shortest possible path to B and ignores the negativeweighted
edge from B to C.
As a result, Dijkstra's algorithm misses the true minimumweight path from A
to B, which passes from A to C to B for a total weight of (2 – 47) = 45.
2.
Our goal is to find the number of minimumweight paths from vertex
v
to each vertex
u
.
We
will denote this number as count[
u
].
There are three cases we need to consider when modifying
Dijkstra's algorithm:
initializing the count table, updating count when we find a new minimum
path, and updating count when we find a duplicate minimum path.
Working with the pseudocode
from the text (figure 9.31), we make the following changes:
●
In the
for each
loop at the beginning of the dijkstra function, we add a line to set count[
v
]
to 0.
●
Within the innermost
if
block, when we update
w
.path to point back to
v
, we will also set
count[
w
] to count[
v
].
In this case, we have found that if we visit
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '08
 M.McCullen
 Algorithms, Graph Theory, Data Structures, Shortest path problem, Dijkstra, B C D E B, Accept Accept Accept

Click to edit the document details