Data Structures & AlgorithmsVery hardGATE CSE · Advanced

A weighted directed graph has edges S->A 6, S->B 7, A->B 8, A->C 5, A->D -4, B->C -3, B->D 9, C->A -2, D->S 2, D->C 7 (it has no negative cycle). What is the shortest distance from S to D?

  1. A. 2
  2. B. -2
  3. C. 0
  4. D. 3

Correct answer: B. -2

Best route is S->B->C->A->D: 7 - 3 - 2 - 4 = -2, better than S->A->D which costs 2; Bellman-Ford finds this after enough relaxation passes.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic