Data Structures & AlgorithmsVery hardGATE CS
Dijkstra's algorithm runs from A on the directed graph A→B (14), A→C (11), A→D (8), A→E (1), A→F (15), B→C (6), B→E (2), B→F (5), C→D (9), C→F (2), D→B (15), D→F (10) (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. 2 times, final 13
- B. 4 times, final 13
- C. 1 time, final 13
- D. 2 times, final 15
Correct answer: A. 2 times, final 13
dist[F] drops only when a newly finalised in-neighbour gives a strictly shorter route; tracing the finalisation order A E D C F B gives 2 decreases ending at 13. 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
- Bellman–Ford runs from A on the directed graph whose edges are relaxed in EVERY pass in this fixed order: E→D (9), A→B (6), F→A (-3), F→D…
- Prim's algorithm starts at D on the weighted undirected graph A–D (23), A–F (5), A–G (28), B–C (17), B–E (15), B–G (2), C–E (21), C–G…
- A binary search tree holds exactly the keys 41, 50, 62, 63, 68, 69, 74, 94. Which ONE of the following can be its POSTORDER traversal?
- A 4-ary max-heap is stored in a 0-indexed array (children of i at 4i + 1 … 4i + 4): [58, 57, 54, 33, 11, 34, 22, 42, 30, 19]. After…
- Keys 33, 11, 72, 19, 76, 71, 31, 74, 40, 37, 45 are inserted in that order into an empty BST. Then 33 is deleted and after that 37 is…
- Keys 90, 94, 89, 30, 62, 17, 99, 53 inserted in this order build a BST. How many of the 8! orderings of these same 8 keys, inserted into…