Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2 C

Directed graph on vertices 0 to 6 with weighted edges (u→v (w)): 6→5 (10), 1→2 (8), 4→2 (7), 2→4 (6), 0→2 (4), 4→3 (5), 1→3 (1), 3→6 (1), 1→4 (8), 5→0 (1), 5→1 (7), 3→1 (1), 4→6 (11), 5→6 (1), 2→1 (6). What is the length of a shortest path from 0 to 6, where the length is the sum of edge weights?

  1. A. 21
  2. B. 2
  3. C. 11
  4. D. 12

Correct answer: D. 12

Dijkstra finalises vertices in increasing distance and gives 12 via 0 → 2 → 1 → 3 → 6. Counting edges instead of weights picks a route with 3 edge(s) and weight 21, which is the common slip.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic