Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
Directed weighted graph on vertices F, E, D, B, C (source F, target C) with edges: F→E (5); F→D (8); D→E (-5); E→C (1); D→C (6); F→C (8); F→B (7). Run Dijkstra from F with a min-heap: a vertex is finalised the first time it is popped, its outgoing edges are relaxed then, and a finalised vertex's distance is never changed afterwards (edges into finalised vertices are ignored). What distance to C does it report?
- A. 4
- B. 14
- C. 8
- D. 6
Correct answer: D. 6
Dijkstra finalises E at distance 5 before the negative edge from D is seen, so it reports 6. The true shortest distance is 4, which goes through the negative edge; clamping negatives to 0 or using their absolute values are other wrong models.
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 trie keeps a counter at each node, and every word of the list W = ['c', 'b', 'baba', 'a', 'b', 'cc', 'ccb', 'cb'] is inserted once per…
- Strings a = "accca" and b = "bcbb". The edit distance allows insert, delete and substitute, each costing 1 (the standard Levenshtein…
- Directed graph on vertices A, B, C, D, E, F, G with edges D→A, A→E, E→F, B→F, B→A, F→G, C→D, D→G, E→B, A→F, A→B (no weights). What is the…
- Bipartite graph with left side {A, B, C}, right side {D, E, F, G} and edges A–D, A–F, B–D, B–F, B–G. What is the size of a maximum…
- Directed weighted graph on vertices A, B, C, D, E with edges (u→v, w): E→C (9); C→D (5); C→E (4); A→C (5); B→E (1); C→A (3); E→A (2); B→C…
- Keys [43, 27, 29, 8, 44, 17, 18, 5, 4] are inserted, in this order, into an empty AVL tree using the standard rebalancing (left, right…