Data Structures & AlgorithmsHardGATE CS · Amazon
A weighted digraph has edges S→A (2), S→B (5), A→C (4), B→A (−4), B→C (1) and C→T (1). Textbook Dijkstra (a vertex's distance is final once it is extracted) is run from S. Which statement is correct?
- A. Dijkstra gives d(T) = 6; the true shortest distance is 6
- B. Dijkstra gives d(T) = 7; the true shortest distance is 6
- C. Dijkstra gives d(T) = 7; the true shortest distance is 7
- D. Dijkstra gives d(T) = 7; the true shortest distance is 5
Correct answer: B. Dijkstra gives d(T) = 7; the true shortest distance is 6
Dijkstra finalises A at 2 and never revisits it when the negative edge B→A would improve it to 1, so C = 6 and T = 7. The true shortest path is S→B→A→C→T = 5 − 4 + 4 + 1 = 6, so negative edges break the greedy proof.
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 graph on vertices a-f has edges ab(1), bc(2), ac(2), cd(3), bd(3), de(1), ce(4), ae(4), ef(2), df(2). How many distinct…
- A directed graph has the vertices A, B, C, D, E, F, G, H, I and the arcs A→E, B→E, B→F, D→C, E→B, E→C, G→E, G→I, H→B, H→F, I→C, I→H. What…
- An undirected connected graph has the vertices A–J and the edges A–H, B–E, C–I, C–J, D–E, E–G, E–I, F–I, G–J, H–I, H–J, I–J. How many…
- A graph has the vertices A–F and the edges A–B, A–C, B–C, B–D, C–D, C–E, D–E, D–F, E–F, A–F. How many distinct spanning trees does it have?
- Floyd's bottom-up build-heap (sift-down from the last internal node back to the root) is applied to the array [55, 25, 49, 27, 3, 17, 33…
- Keys 50, 20, 60, 10, 30, 40, 70, 45, 42, 48, 5, 3 are inserted one by one, in this order, into an initially empty AVL tree. A double…