Data Structures & AlgorithmsVery hardProduct-company placement
Dijkstra's algorithm runs from A on the directed graph A→B (6), A→E (1), A→F (11), B→C (9), B→D (2), B→F (1), C→D (10), C→F (11), D→A (5), D→F (3), E→D (4), F→E (15) (relaxations into already-finalised vertices are skipped). How many times is dist[F] lowered (counting the first change from ∞), and what is its final value?
- A. 4 times, final 7
- B. 2 times, final 7
- C. 3 times, final 11
- D. 3 times, final 7
Correct answer: D. 3 times, final 7
dist[F] drops only when a newly finalised in-neighbour gives a strictly shorter route; tracing the finalisation order A E D B F C gives 3 decreases ending at 7. It is not simply the in-degree (4).
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
- With 3 identical eggs and at most 7 drops, what is the largest number of floors for which you can always determine the critical floor (the…
- 0/1 knapsack with capacity 18: items (weight, value) = (8, 39), (2, 16), (3, 24), (6, 38), (3, 36). What is the maximum total value?
- Six sorted files have 8, 23, 33, 38, 42, 49 records. Merging two files of sizes a and b costs a + b. What is the minimum total cost to…
- Kruskal's algorithm runs on the weighted undirected graph A–B (15), A–F (7), A–G (21), B–C (17), B–D (23), B–F (22), D–F (8), E–F (13)…
- A complete binary tree (array form, all levels full except possibly the last, which is filled from the left) has 131 nodes. How many…
- Six sorted files have 10, 12, 13, 21, 23, 42 records. Merging two files of sizes a and b costs a + b. What is the minimum total cost to…