Shortest Paths Help Center

Learn more

Warning: The hard deadline has passed. You can attempt it, but you will not get credit for it. You are welcome to try it as a learning exercise.

To specify an array or sequence of values in an answer, separate the values in
the sequence by whitespace. For example, if the question asks for the first
ten powers of two (starting at 1), then the following answer is acceptable:

1 2 4 8 16 32 64 128 256 512

If you wish to discuss a particular question and answer in the forums, please
post the entire question and answer, including the seed (which can be used by
the course staff to uniquely identify the question) and the explanation (which
contains the correct answer).

Question 1

(seed = 856092)
Consider the following edge-weighted digraph with 8 vertices and 13 edges.

v->w weight
------------
A->E 37
B->A 6
B->C 10
B->E 45
B->G 5
D->C 27
D->H 12
F->B 39
F->E 89
F->G 16
G->C 43
G->D 9
G->H 31


Here is a graphical representation of the same edge-weighted digraph:

(A)<-----6------(B)------10---->(C)<-----27-----(D)
| /^\ ^ ^|
| / | \ | / |
| / | \ | / |
| / | \ | / |
| / | \ | / |
| / | \ | / |
| / | \ | / |
37 45 39 5 43 9 12
| / | \ | / |
| / | \ | / |
| / | \ | / |
| / | \ | / |
| / | \ | / |
| / | \ | / |
vv | v|/ v
(E)<-----89-----(F)------16---->(G)------31---->(H)



Suppose that you run Dijkstra's algorithm to compute the shortest paths
from F to every other vertex. Give the sequence of 8 integers in the
distTo[] array immediately after vertex B is relaxed.

Here is the distTo[] array before F is relaxed:

v A B C D E F G H
------------------------------------------
distTo[v] - - - - - 0 - -

Question 2

(seed = 388830)
Consider the following edge-weighted DAG with 8 vertices and 13 edges.

v->w weight
------------
A->E 2
A->F 3
B->A 33
B->F 5
C->B 35
C->D 23
C->G 24
F->E 4
G->B 7
G->F 9
H->C 16
H->D 46
H->G 47


Here is a graphical representation of the same edge-weighted digraph:

(A)<-----33-----(B)<-----35-----(C)------23---->(D)
|\ |^ |^ ^
| \ | \ | \ |
| \ | \ | \ |
| \ | \ | \ |
| \ | \ | \ |
| \ | \ | \ |
| \ | \ | \ |
2 3 5 7 24 16 46
| \ | \ | \ |
| \ | \ | \ |
| \ | \ | \ |
| \ | \ | \ |
| \ | \ | \ |
| \ | \ | \ |
v vv \v \|
(E)<-----4------(F)<-----9------(G)<-----47-----(H)



Suppose that you run the acyclic shortest paths algorithm to compute the shortest
paths from H to every other vertex using the following topological order:

H C G D B A F E

Give the sequence of 8 integers in the distTo[] array immediately after
vertex A is relaxed.

Here is the distTo[] array before H is relaxed:

v A B C D E F G H
------------------------------------------
distTo[v] - - - - - - - 0

Question 3

(seed = 194047)
Consider the following edge-weighted digraph with 8 vertices and 13 edges.

v->w weight
------------
A->F 3
A->E 2
B->A 27
B->C 1
C->F 4
D->C 56
D->H 32
F->E 16
F->B 13
G->F 10
G->C 18
H->C 19
H->G 6


Here is a graphical representation of the same edge-weighted digraph:

(A)<-----27-----(B)------1----->(C)<-----56-----(D)
|\ ^ /^^ |
| \ | / | \ |
| \ | / | \ |
| \ | / | \ |
| \ | / | \ |
| \ | / | \ |
| \ | / | \ |
2 3 13 4 18 19 32
| \ | / | \ |
| \ | / | \ |
| \ | / | \ |
| \ | / | \ |
| \ | / | \ |
| \ | / | \ |
v v|v | \v
(E)<-----16-----(F)<-----10-----(G)<-----6------(H)



Suppose that you run the Bellman-Ford algorithm to compute the shortest paths
from D to every other vertex. Give the sequence of 8 integers in the distTo[]
array immediately after the end of three passes of the algorithm (pass 0, 1, and 2).
Each pass consists of relaxing the 13 edges in the order given above.

Here is the distTo[] array before the beginning of pass 0:

v A B C D E F G H
------------------------------------------
distTo[v] - - - 0 - - - -
    
You cannot submit your work until you agree to the Honor Code. Thanks!