GATE / CS ARCHIVE

GATE CSE 2008 / QUESTION 45

Dijkstra on the given negative-edge graph

Algorithms · Graph Algorithms · Full GATE CSE 2008 paper

GATE 2008, Q45 2 marks · MCQ
Report issue

Graph Algorithms

Question 45, GATE 2008: Run Dijkstra from a in this directed weighted graph: a→b:1, b→c:2, c→d:3, d→a:2, b→e:−3, c→h:−5, d→g:2, h→e:1, g→h:2, g→e:1, e→f:2, f→g:3. To which vertices does it compute correct shortest-path distances?

(A) Only a
(B) Only a,e,f,g,h
(C) Only a,b,c,d
(D) All vertices
Tap to enlarge
Your answer
Answer & solution

Answer: D (no official key was published)

Step through it (22 steps)

1. All vertices receive the correct distance despite the negative edges. From a, settle b at 1, which sets c=3 and e=−2. Settle e at −2, then f at 0, setting g=3. Vertices c and g tie at 3.
2. Whichever is handled first, c sets h=3−5=−2 before h is settled (if g was handled first it only proposes h=5). Vertex h proposes e=−1, not an improvement over −2. Vertex d gets 6 from c and offers no improvement to a or g. Final distances (a,b,c,d,e,f,g,h)=(0,1,3,6,−2,0,3,−2).
3. They also satisfy every edge relaxation inequality, with each value attained by a path, proving optimality. Negative edges invalidate Dijkstra’s general guarantee, but do not force failure on every particular input.

Original paper, page 8