Data Structures & AlgorithmsVery hardGATE CS
Dijkstra's algorithm runs from A on the directed graph A→C (4), A→D (15), B→A (2), B→C (13), C→D (8), C→E (7), C→F (2), D→B (12), E→B (7), F→A (13), F→D (8), F→E (2) (relaxations into already-finalised vertices are skipped). How many times is dist[D] lowered (counting the first change from ∞), and what is its final value?
- A. 3 times, final 12
- B. 2 times, final 12
- C. 1 time, final 12
- D. 2 times, final 15
Correct answer: B. 2 times, final 12
dist[D] drops only when a newly finalised in-neighbour gives a strictly shorter route; tracing the finalisation order A C F E D B gives 2 decreases ending at 12. It is not simply the in-degree (3).
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
- Floyd–Warshall runs on vertices 1–4 with directed edges 1→2 (2), 1→3 (8), 2→1 (8), 2→4 (3), 3→2 (7), 3→4 (6), 4→1 (2). After the…
- A tree on vertices 1–9 has edges 2–1, 3–2, 4–2, 5–2, 6–5, 7–4, 8–5, 9–7. What are its diameter and radius, and which vertex/vertices form…
- An undirected graph has edges A–E, A–G, A–H, B–H, C–E, D–F, D–H, E–G, F–H, G–H. BFS starts at A and always scans neighbours in…
- Lectures occupy half-open intervals [start, end): [2, 7), [6, 11), [8, 14), [9, 14), [10, 16), [13, 16), [13, 20), [14, 20). A lecture…
- A binary tree with distinct labels has INORDER D F I E A C H G B and LEVEL-ORDER D G C B E H F A I. What is its postorder traversal?
- A binary search tree holds exactly the keys 10, 17, 35, 59, 61, 68, 84, 91. Which ONE of the following sequences can be its PREORDER…