Data Structures & AlgorithmsVery hardICPC regional · GATE CS top band
Directed weighted graph on vertices C, F, E, D, A (source C, target A) with edges: C→F (5); C→E (7); E→F (-4); F→A (1); E→A (1); C→A (7); C→D (5). Run Dijkstra from C 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 A does it report?
- A. 4
- B. 12
- C. 3
- D. 6
Correct answer: D. 6
Dijkstra pops F at 5 and finalises it, then A at 6 via F; when E (7) is popped later, the edge E→F (−4) cannot improve the finalised F, so it reports 6. The true shortest is C→E→F→A = 4, 3 is the true distance to F, and using |−4| gives 12 via E.
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
- 2 × 3 sliding puzzle with tiles 1 to 5 and one blank (shown as ). Current board: 2 5 / 1 3 4. Goal board: 1 2 3 / 4 5 . A move slides a…
- Array [10, 28, 18, 27, 13, 14] is turned into a min-heap in place with bottom-up heapify: for i from ⌊n/2⌋−1 down to 0, sift the element…
- Array A = [3, 31, 23, 2, 8, 19, 7] (all values below 32). What is the maximum of A[i] XOR A[j] over all index pairs with 0 ≤ i < j < 7?
- Distinct keys [5, 4, 7, 27, 25] are inserted, in the order given by the sequence [25, 5, 4, 27, 7], into an empty binary search tree. How…
- Consider the recursive function def f(n): if n < 2: return n; return f(n-1) + f(n-2). Evaluate f(7) and count every invocation of f…
- Consider the recursive function def f(n): if n < 2: return n; return f(n-1) + f(n-2). Evaluate f(10) and count every invocation of f…