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?
- A. Dijkstra's algorithm, O((V + E) log V)
- B. Floyd-Warshall, O(V^3), for single-source paths
- C. Bellman-Ford, O(VE), required because of negative weights
- 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
- Problem: A graph may contain negative edge weights but no negative cycle. Which single-source shortest path algorithm handles this…
- Problem: What is the time complexity of the Floyd-Warshall algorithm for finding shortest paths between every pair of nodes in a graph…
- Problem: Which of these best describes why Kruskal's MST algorithm needs a Union-Find (disjoint set) structure?
- Problem: Between Kruskal's and Prim's MST algorithms, which is typically preferred for a dense graph represented with an adjacency matrix?
- Problem: Which statement correctly contrasts 0/1 knapsack and fractional knapsack?
- Problem: Activity selection (pick the maximum number of non-overlapping intervals from a set) is solved optimally by which greedy strategy?