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

() Dv n lrthm t fnd th hrtt pth btwn tw vrtc, umn th rph cyclc. Yur lrthm huld m

ID: 3765736 • Letter: #

Question

() Dv n lrthm t fnd th hrtt pth btwn tw vrtc, umn th rph cyclc. Yur lrthm huld mk xctly n cll t th Bllmn-Frd lrthm. Hnt: u th fct tht l( · b) = l + l b t cntruct rph tht Bllmn-Frd cn lv.

(b) Dv n lrthm t fnd th lnt pth un n cll t Djktr’ lrthm.

NOTE: I AM NOT LOOKING FOR CODE but an actual algorithm(i.e English) i.e. I want the thinking behind coming up with the algorithms. You do not have to explain to me what Bellman-Ford or Dijkstra is, but explain to me how you come with an algorithm that solves the problem at hand.

Explanation / Answer

(a)
Shortt path btwn tw vrtc, aumng th graph acyclc.

The Bellman ford algorithm is used to find shortest path, and it is more versatile in a way that it can handle negative weights.

Steps to find shortest path :
1). Call BellMan Ford algorithm with a source node. An adjacency matrix will be returned.
2). Fetch the distance between corresponding vertices .
Note- Modify the Bellman Ford code to compute length of path with multiplication, instead of addition.


(b)
Lngt Path ung n call t Djktra’ algrthm

Case A :
"the longest path problem is NP-hard, meaning that it cannot be solved in polynomial time for arbitrary graphs unless P = NP"

Case B :
Steps to find Longest Path :
(1). Find a topological ordering of the given DAG(Directed Acyclic Graph).

(2). Either (a) or (b)
(a). Call to Dijkstra with a change in condition. Look for neighbour which contribute to a bigger distance
new distance = (old_distance * max(weight of neighbour))
(b). For each vertex v of the DAG, in the topological ordering, compute the length of the longest path ending at v by looking at its incoming neighbors and multiplying the maximum length recorded for those neighbours.
* If v has no neighbors(isolated vertex), then length of the longest path ending at v will be one.