• edited by
24,869 views
55 55 votes

Suppose we run Dijkstra’s single source shortest path algorithm on the following edge-weighted directed graph with vertex $P$ as the source.

In what order do the nodes get included into the set of vertices for which the shortest path distances are finalized?

  1. $P,Q,R,S,T,U$
  2. $P,Q,R,U,S,T$
  3. $P,Q,R,U,T,S$
  4. $P,Q,T,R,U,S$

4 Answers

Best answer
41 41 votes

Answer is (B). In Dijkstra's algorithm at each point we choose the vertex with the shortest distance from the set of vertices in the shortest path found so far and add the edge connecting it to the shortest path.

• edited by
1 1 vote
\[
\text{Just select the Minimum at each level , it will be the order of the finalization of the nodes.

This is the approach that's why priority queue is used in Dijkstra it selects the finalized (minmum)}
\]

\[
\begin{array}{|c|c|c|c|c|c|c|}
\hline
\textbf{Step} & \textbf{Finalized Node} & \textbf{Distance} & B & C & D & E \\
\hline
0 & - & A=0 & \infty & \infty & \infty & \infty \\
1 & A & A=0 & 4 & \infty & \infty & \infty \\
2 & B & B=4 & 4 & 6 & \infty & \infty \\
3 & C & C=6 & 4 & 6 & 7 & \infty \\
4 & D & D=7 & 4 & 6 & 7 & 9 \\
5 & E & E=9 & 4 & 6 & 7 & 9 \\
\hline
\end{array}
\]
 
Answer:
Position:
Show:

Related questions

39 39 votes
8 answers 8 answers
15.8k
15.8k views
Kathleen asked Oct 9, 2014
15,835 views
Let $G$ be the directed, weighted graph shown in below figureWe are interested in the shortest paths from $A$.Output the sequence of vertices identified by the Dijkstra’s...
114 114 votes
11 answers 11 answers
44.8k
44.8k views
gatecse asked Sep 26, 2014
44,750 views
Consider the directed graph shown in the figure below. There are multiple shortest paths between vertices $S$ and $T$. Which one will be reported by Dijkstra’s shortest p...
76 76 votes
3 answers 3 answers
26.4k
26.4k views
Kathleen asked Sep 22, 2014
26,448 views
Let $G(V,E)$ be an undirected graph with positive edge weights. Dijkstra’s single source shortest path algorithm can be implemented using the binary heap data structure w...
86 86 votes
12 answers 12 answers
50.5k
50.5k views
Kathleen asked Sep 12, 2014
50,521 views
Dijkstra's single source shortest path algorithm when run from vertex $a$ in the above graph, computes the correct shortest path distance toonly vertex $a$only vertices $...