Data Structures & AlgorithmsVery hardICPC regional · GATE CS top band
Directed weighted graph on vertices B, F, A, C, D (source B, target D) with edges: B→F (2); B→A (5); A→F (-4); F→D (1); A→D (3); B→D (12); B→C (7). Run Dijkstra from B 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 D does it report?
- A. 8
- B. 12
- C. 3
- D. 2
Correct answer: C. 3
Dijkstra finalises F at distance 2 before the negative edge from A is seen, so it reports 3. The true shortest distance is 2, 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
- Distinct words ['cc', 'aab', 'a', 'cbc', 'bbb', 'bc'] are inserted into an empty trie (one node per character, shared prefixes share…
- 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)…
- 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…