Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
Directed weighted graph on vertices A, D, C, E, F (source A, target F) with edges: A→D (5); A→C (6); C→D (-6); D→F (4); C→F (4); A→F (14); A→E (5). 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 F does it report?
- A. 4
- B. 9
- C. 10
- D. 14
Correct answer: B. 9
Dijkstra finalises D at distance 5 before the negative edge from C is seen, so it reports 9. 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 graph on vertices A, B, C, D, E, F with edges A→C, A→D, E→A, D→E, B→D, F→D, D→C, C→A, E→B, F→B (no weights). What is the number…
- Distinct words ['acca', 'cca', 'bb', 'ca', 'cba', 'aa'] are inserted into an empty trie (one node per character, shared prefixes sharing…
- Array A = [9, 8, 3, 6, 4, 2, 6] (indices 0 to 6). Count the non-empty subsets of positions (each position used at most once, subsets not…
- Connected undirected weighted graph on vertices A, B, C, D, E with edges A–B (12), A–C (1), A–E (10), B–D (18), B–E (13), C–D (13), D–E…
- Words ['aaac', 'bac', 'cb', 'ac', 'baab', 'bc', 'bac'] are inserted in this order into an empty trie with one node per character, shared…
- Directed graph on vertices A, B, C, D, E, F with edges F→C, B→A, C→F, D→B, B→F, A→E, E→F, A→C, B→D (no weights). What is the number of…