Data Structures & AlgorithmsHardProduct-company MCQ pattern

How many of these statements are correct? (i) Dijkstra's algorithm with a binary heap runs in O((V + E) log V). (ii) Bellman–Ford runs in O(VE). (iii) Floyd–Warshall works with negative edge weights as long as there is no negative cycle. (iv) Dijkstra's algorithm always gives correct distances on graphs with negative edges, provided there is no negative cycle.

  1. A. Only one
  2. B. Only two
  3. C. Only three
  4. D. All four

Correct answer: C. Only three

(i), (ii) and (iii) are true. (iv) is false: Dijkstra finalises a vertex when it is popped, and a later negative edge can make a cheaper path to that vertex, which it never revisits.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic