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.
- A. Only one
- B. Only two
- C. Only three
- 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.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- Directed edges: A→B (2), A→C (5), C→B (−4), B→D (1). Dijkstra's algorithm, which finalises each vertex once when it is removed from the…
- DFS is run on a directed graph with edges A→B, A→C, B→D, C→D, C→A, D→B, E→C, E→D, starting from A, taking vertices and neighbours in…
- Kahn's algorithm is run on the DAG with edges 5→2, 5→0, 4→0, 4→1, 2→3, 3→1, always removing the SMALLEST-numbered vertex of in-degree 0 (a…
- How many topological orderings does the DAG with edges A→B, A→C, B→D, C→D, D→E, B→F have?
- Prim's algorithm starts at A on the undirected graph with edges A–B (3), A–C (1), B–C (7), B–D (5), C–D (2), C–E (7), D–E (3), D–F (8)…
- An undirected graph on A, B, C, D has edges A–B, B–C, C–D, D–A of weight 1 and a diagonal A–C of weight 2. How many distinct minimum…