The GATE Grind

GATE 2010 CS (CS1) – Question 61

Algorithms · Graph Algorithms: Traversals, Minimum Spanning Trees, Shortest Paths · 2 marks · Multiple choice

The undirected graph on vertices 0,…,4 has weight matrix $$W=\begin{pmatrix}0&1&8&1&4\\1&0&12&4&9\\8&12&0&7&3\\1&4&7&0&2\\4&9&3&2&0\end{pmatrix}.$$ Find the shortest path weight from vertex 1 to vertex 2 using at most three edges.

  1. 7
  2. 8
  3. 9
  4. 10

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: (B) 8

Explanation

A three-edge path 1→0→4→2 has weight 1+4+3=8. The unconstrained shortest route 1→0→3→4→2 weighs seven but uses four edges and is ineligible. Checking one-edge and two-edge routes gives at least eleven; other three-edge routes cannot improve eight. Thus B.

More Graph Algorithms: Traversals, Minimum Spanning Trees, Shortest Paths questions

All Graph Algorithms: Traversals, Minimum Spanning Trees, Shortest Paths questions →