🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Shortest Paths: all 10 questions

Quiz: Shortest Paths · Question 3 of 10

Why can't Dijkstra's algorithm handle negative edge weights?

Why can't Dijkstra's algorithm handle negative edge weights?

  1. A.The heap cannot store negative numbers
  2. B.It treats the smallest popped distance as final, but a negative edge found later could still lower it
  3. C.It runs forever
  4. D.It can; negative edges only make it slower
Answer & explanation

Correct answer: It treats the smallest popped distance as final, but a negative edge found later could still lower it

With negative edges, a longer-looking path can end up cheaper after the node is already settled.

Can you get the rest right without peeking?

Take the timed Quiz: Shortest Paths quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →