Question: UESTION FOUR [12MARKS] a) The Dijkstra's algorithm present below uses the greedy method to compute the shortest route of a graph. Carefully study the algorithm
UESTION FOUR [12MARKS] a) The Dijkstra's algorithm present below uses the greedy method to compute the shortest route of a graph. Carefully study the algorithm and use it to compute the shortest distance/route from a source node, D. [10marks] b) Draw the minimum spanning tree for the graph using Prim's algorithm. [2marks] Algorithm: Dijkstra's-Algorithm (G, w, s) for each vertex v G.V v.d : = v. : = NIL s.d :=0 S:= Q:=G.V while Q= u:= Extract-Min (Q) S:=SU{u} for each vertex v G.adj [u] if v.d>u.d+w(u,v) v.d:=u.d+w(u,v) v.:=u UESTION FOUR [12MARKS] a) The Dijkstra's algorithm present below uses the greedy method to compute the shortest route of a graph. Carefully study the algorithm and use it to compute the shortest distance/route from a source node, D. [10marks] b) Draw the minimum spanning tree for the graph using Prim's algorithm. [2marks] Algorithm: Dijkstra's-Algorithm (G, w, s) for each vertex v G.V v.d : = v. : = NIL s.d :=0 S:= Q:=G.V while Q= u:= Extract-Min (Q) S:=SU{u} for each vertex v G.adj [u] if v.d>u.d+w(u,v) v.d:=u.d+w(u,v) v.:=u
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
