Data Structures & AlgorithmsHardCAT · GATE CS

Problem: For a weighted graph with all non-negative edge weights, which algorithm finds shortest paths from a single source, and in what time with a binary heap?

  1. A. Dijkstra's algorithm, O((V + E) log V)
  2. B. Floyd-Warshall, O(V^3), for single-source paths
  3. C. Bellman-Ford, O(VE), required because of negative weights
  4. D. BFS, O(V + E), ignoring edge weights

Correct answer: A. Dijkstra's algorithm, O((V + E) log V)

Dijkstra's algorithm greedily extracts the closest unvisited node using a priority queue; with a binary heap this runs in O((V+E) log V). It requires non-negative weights to be correct.

More Coding Interview Problems questions

Exams that ask this topic