Curated · Graph Traversals (BFS & DFS)

MCQ · 2 marks · Problem PROG-GRPH-0128

Dijkstra's algorithm is greedy. In which situation can it give a WRONG shortest-path answer?
  1. A
    When some edge weights are negative
  2. B
    When the graph has cycles
  3. C
    When the graph is undirected
  4. D
    When two paths have equal length

Solve it on GATE DA practice →More Graph Theory & Algorithms problems

Show the worked solutionDijkstra's algorithm fixes a vertex's distance as final the moment the vertex is picked as the closest unvisited one. That is safe only if no path found later can be shorter.With a negative edge, a path through a vertex picked later can still lower the distance of a vertex already fixed, and Dijkstra never revisits it. So the answer can be wrong.Cycles, undirected graphs and ties are all handled correctly. For negative edges (without negative cycles), use Bellman-Ford.Answer: When some edge weights are negativeClick to Join Our Telegram Group for Latest Update of MOCK TEST Click Here to Practice ALL Previous MOCK TEST FREE

GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com