Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div 2
Directed weighted graph on vertices A, D, B, F, C (source A, target C) with edges: A→D (4); A→B (7); B→D (-6); D→C (3); B→C (1); A→C (12); A→F (7). Run Dijkstra from A 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. 8
- B. 12
- C. 7
- D. 4
Correct answer: C. 7
Dijkstra finalises D at distance 4 before the negative edge from B is seen, so it reports 7. 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
- Directed acyclic graph on vertices A, B, C, D, E with edges A→D, A→C, D→B, D→C. Among all topological orderings (every edge goes from…
- Words ['b', 'b', 'b', 'c', 'cbca', 'aca'] are inserted in this order into an empty trie with one node per character, shared prefixes…
- Connected undirected weighted graph on vertices A, B, C, D, E, F with edges A–D (5), B–D (7), B–F (13), C–D (11), D–E (11), D–F (12), E–F…
- Directed graph on vertices A, B, C, D, E, F, G with edges E→F, C→G, B→E, E→D, E→G, C→E, F→D, C→A, D→A, F→E. How many strongly connected…
- Directed graph on vertices A, B, C, D, E, F with edges C→F, D→E, D→B, F→B, F→C, E→C, F→E, E→A (no weights). What is the number of vertices…
- Connected undirected weighted graph on vertices A, B, C, D with edges A–B (6), A–C (1), A–D (1), B–C (3), B–D (6), C–D (4). Among all…