• edited by
43,970 views
108 108 votes

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 path algorithm? Assume that, in any iteration, the shortest path to a vertex $v$ is updated only when a strictly shorter path to $v$ is discovered.

  1.  $\text{SDT}$
     
  2.  $\text{SBDT}$
     
  3.  $\text{SACDT}$
     
  4.  $\text{SACET}$

11 Answers

Best answer
84 84 votes

Relaxation at every vertex is as follows:

Note that the next picked vertex corresponds to the next row in Table
$$\scriptsize{\begin{array}{|c|c|} \hline \text{} & \textbf{A} & \textbf{B} & \textbf{C} & \textbf{D} & \textbf{E} & \textbf{F} & \textbf{G} & \textbf{T} \\\hline 
\textbf{S} & \text{4} &  \boxed{\text{$3$}} & \text{$\infty$} & \text{7} & \text{$\infty$} & \text{$\infty$} & \text{$\infty$} & \text{$\infty$}\\
&S\to A&\boxed{\bf{S\to B}}&&S \to D\\
\\\hline  
\textbf{B} &  \boxed{\text{$4$}} &  & \text{$\infty$} & 7 & \text{$\infty$} & \text{$\infty$} & \text{$\infty$} & \text{$\infty$}\\
&\boxed{\bf{S \to A}} &&& S \to D  \\\hline 
\textbf{A} & \text{} &  \text{} & \boxed{5} & \text{7} & \text{$\infty$} & \text{$\infty$} & \text{$\infty$} & \text{$\infty$}\\
&&&\boxed{\bf{S\to A \to C}}&S \to D
\\\hline 
\textbf{C} & \text{} &  \text{} & \text{} & \text{7} & \boxed{6} & \text{$\infty$} & \text{$\infty$} & \text{$\infty$}\\
&&&&S \to D&\boxed{\bf{S\to A\\\to C\to E}}\\
\hline 
\textbf{E} & \text{} &  \text{} & \text{} & \boxed{\text{$7$}} & \text{} & \text{$\infty$} & \text{$8$} & \text{$10$} \\
&&&&\boxed{\bf{S \to D}}&&&S\to A \to C &S\to A \to C
\\&&&&&&&\to E \to G &  \to E \to T
\\ \hline  
\textbf{D} & \text{} &  \text{} & \text{} & \text{} & \text{} & \text{$12$} & \boxed{8} & \text{$10$}\\
&&&&&&{S \to D \to F}&\boxed{\bf{S\to A \to C\\ \to E \to G}}&S\to A \to C\\
&&&&&&&& \to E \to T
\\\hline  
\textbf{G} & \text{} &  \text{} & \text{} & \text{} & \text{} & \text{12} & \text{} & \boxed{10}
\\
&&&&&&{S \to D \to F}&&\boxed{\bf{S\to A \to C \\\to E \to T}}
\\\hline  
\textbf{T} & \text{} &  \text{} & \text{} & & \text{} & \boxed{\text{12}} & \text{} & \text{}\\
&&&&&&\boxed{\bf{S \to D \to F}}&\\
\hline \end{array}}$$

For $S$ to $T$ shortest path is $\boxed{S \to A \to C \to E \to T}$

Option : D

• edited by
54 54 votes

Chosen answer is best one but many people have doubt that why B is not selected as it is shortest than A.

Answer to this is when we run dijkstra algorithm 

First S will update A ,B,D as 4,3,7 respectively.

then we select shortest of it i.e B (3). After there is nothing for B to relax and give better update.as D is already updated by S with weight  7. 

So now it will select A . it will relax C and so on...

S-B-A-C-E-D-G-T-F.

please follow given tree. how algorithm will proceed and relax.

 

                                                             S

                                                    /         \         \

                                                 A          B          D

                                                /                           \

                                             C                              F

                                              |

                                             E

                                          /      \

                                       G         T

There for shortest path using Dijkstra Algorithm is SACET.

14 14 votes

Dijkstra algorithm is such that it selects shortest edge for adjacent nodes.

It selects shortest path having maximum number of shortest edges, for non adjacent.

Answer seems to be D. could be checked directly.

2 flags:
✌ Low quality (js__ “2nd line is misleading or incomplete.”)
✌ Spam (Vignan)
2 2 votes
Ans is d

But its taking too much time for me to get the ans..what is the best way to solve this question with optimal time.can any1 suggest
1 1 vote

Statement  ""IN ANY ITERATION ,THE SHORTEST PATH TO A VERTEX V IS UPDATED ONLY WHEN A STRICTLY SHORTEST PATH TO V IS DISCOVERED"""​​​​​​​

 that means we have to considered only such node whose relaxation can affect/reduces /(changes to min. value than earlier)  other neighbouring  nodes along with that  it must be in shortest path(  i.e.  while relaxation of D it reduces the node value of F but cant reduces the value of T  , therefore it is not considered)

Answer:
Position:
Show:

Related questions

37 37 votes
8 answers 8 answers
15.2k
15.2k views
Kathleen asked Oct 9, 2014
15,200 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...
74 74 votes
3 answers 3 answers
26.0k
26.0k views
Kathleen asked Sep 22, 2014
25,986 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...
53 53 votes
4 answers 4 answers
24.6k
24.6k views
Kathleen asked Sep 18, 2014
24,623 views
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...
84 84 votes
12 answers 12 answers
49.5k
49.5k views
Kathleen asked Sep 12, 2014
49,475 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 $...