Data Structures & AlgorithmsVery hardHCLTech · Wipro pattern
Directed edges: A→B (5), A→C (6), C→B (-3), B→D (1). Dijkstra's algorithm, which finalises each vertex once when it is removed from the priority queue, is run from A. What distance does it report for D, and what is the true shortest distance?
- A. Reports 4; true distance 4
- B. Reports 4; true distance 6
- C. Reports 6; true distance 4
- D. Reports 6; true distance 6
Correct answer: C. Reports 6; true distance 4
Dijkstra finalises B before exploring the negative edge C→B, so it never lowers B's distance again even though C→B would give a shorter path; this gives a reported distance of 6 for D, while the true shortest distance (allowing the negative edge to be used) is 4. Dijkstra does not work correctly with negative edge weights.
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
- An undirected connected graph has edges A–B, B–C, C–D, D–E, E–F, F–G, G–H, D–F, F–H. How many articulation points (cut vertices) and how…
- Keys 14, 21, 49, 22, 15, 16, 33, 66 are inserted via separate chaining (h(k) = k mod 7, new keys appended to the end of the chain) into a…
- An undirected connected graph has edges A–B, B–C, C–D, D–E, E–F. How many articulation points (cut vertices) and how many bridges does it…
- Keys 50, 60, 70 are inserted in this order into an empty AVL tree. After AVL rebalancing (a single rotation resolves the imbalance here)…
- Directed edges: A→B (6), A→C (6), C→B (-5), B→D (1). Dijkstra's algorithm, which finalises each vertex once when it is removed from the…
- Keys 38, 13, 87, 73, 18, 97, 3, 68, 72, 98 are inserted via separate chaining (h(k) = k mod 7, new keys appended to the end of the chain)…