Data Structures & AlgorithmsVery hardGATE CS · Advanced
Dijkstra's algorithm (a vertex is settled when removed from the priority queue and its distance is never changed afterwards) is run from A on the directed graph with arcs (weights in brackets): A→B (9), A→G (8), B→G (-6), C→B (2), C→D (7), D→F (6), E→A (4), E→F (6), F→D (9), F→G (3), G→C (6), G→D (2). Exactly one arc has a negative weight and there is no negative cycle. By how much does the distance Dijkstra reports for G exceed the true shortest distance from A to G?
- A. 5
- B. 8
- C. 7
- D. 3
Correct answer: A. 5
Bellman-Ford gives the true distance 3, but Dijkstra settles a vertex before the negative arc can improve it and reports 8, so the excess is 5.
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
- A directed graph on the vertices A–E has the arcs C→B, C→A, B→C, B→E, B→A, D→E, E→B, E→A, A→C, A→B, A→D. Every vertex has equal in-degree…
- Every node of a binary tree has either 0 or 2 children. Its preorder traversal is W S M Q R P K Z T and its postorder traversal is Q R M K…
- A graph has the vertices A–G and the edges A–B, A–C, A–D, B–D, B–F, B–G, C–D, C–F, C–G, D–F, E–F. In how many ways can the vertices be…
- Floyd-Warshall is run on a directed graph with vertices 1-6 and arcs (weights): 1→2 (9), 1→3 (8), 1→4 (8), 1→5 (1), 2→5 (3), 2→6 (8), 3→1…
- A flow network has source S = A and sink T = G (vertices A–G) with arcs and capacities: A→D (1), A→E (6), A→G (6), B→C (2), B→E (5), C→F…
- How many structurally different binary search trees can be built on the keys 1, 2, ..., 8 (all distinct shapes, one per key set) whose…