
I have tried to understand the question but I got really confused.
So starting from node 3, the distance to other nodes are
3 to 1 = 3
3 to 2 = 1
3 to 4 = 4
3 to 5 = 2
3 to 6 = 3
3 to 7 = 2
and the question asks what is the third node added to the set S.
What I think it should be is 2->5->7->1->6->4 therefore the answer should be (B.7)
but the actual answer is (A.5)
Where did I made a mistake with the question?
Here is how the algorithm works:
$$ \begin{array}{c|c} & 1 & 2 & 3 & 4 & 5 & 6 & 7 \\ \hline 3 & \infty & 1 & 0 & \infty & \infty & 9 & 2\\ \hline 2 & 3 & 1 & 0 & \infty & 2 & 6 & 2 \end{array} $$
So at the next step algorithm will choose $5$ because it's current distance is minimal ($5 < 7$ breaks the tie) and it's not in $S$.