Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You are given a black box Dijkstra’s implementation You are given a black box Di

ID: 3779887 • Letter: Y

Question

You are given a black box Dijkstra’s implementation

You are given a black box Dijkstra's implementation, D, that takes as input a directed graph G = (V, E), vertices u. v element V, and weighing function W: E rightarrow R^+ and computes the shortest path between the vertices u, v using the costs returned by W. It is common to want to compute the shortest path of a graph where the path-cost is the product of all the edge-costs in the path instead of the sum of the edge costs. However, since we already have an implementation of Dijkstra's using sum costs, we do not wish to duplicate work. Give an algorithm P that on input P(G, W, u, v) with W: E rightarrow Z^+, computes the shortest product path using D to do most of the work.

Explanation / Answer

computing shortest path :

n<--- rows[W]

D(0)<--W

for k<---1 to n

do for i<-- 1 to n

                    do for j <--- 1 to n

                     dij(k) <--- min (dij(k-1), dik(k-1) + dkj(k-1))

return D(n)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote