Data Structures & AlgorithmsVery hardGATE CS · Product-company placement
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 (8), C→E (-2), E→F (8), A→D (-2), A→C (6), D→C (7). It stops early after the first pass that changes nothing. How many passes change at least one distance, and what is the final distance to F?
- A. 5 passes, dist 11
- B. 3 passes, dist 11
- C. 2 passes, dist 11
- D. 1 pass, dist 11
Correct answer: C. 2 passes, dist 11
Simulate pass by pass in the given edge order: a change can travel along several edges in one pass when they appear in path order, so only 2 passes change something (then one pass confirms nothing changes). Final distances: A=0, B=6, C=5, D=-2, E=3, F=11.
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
- 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…
- A binary search tree holds exactly the keys 13, 19, 20, 36, 71, 73, 94, 99. Which ONE of the following sequences can be its PREORDER…