Data Structures & AlgorithmsVery hardProduct-company placement
Bellman–Ford runs from A on the directed graph whose edges are relaxed in EVERY pass in this fixed order: D→B (4), F→D (8), D→C (2), A→E (7), A→C (-1), B→F (7), A→D (5), B→A (8), F→A (9). 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 16
- B. 3 passes, dist 16
- C. 2 passes, dist 16
- D. 1 pass, dist 16
Correct answer: C. 2 passes, dist 16
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=9, C=-1, D=5, E=7, F=16.
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
- A B-tree has minimum degree t = 4 (every non-root node has between 3 and 7 keys) and height 2 (a root-only tree has height 0). What are…
- The weighted undirected graph A–B (6), A–D (16), A–E (19), A–F (12), B–E (1), B–F (2), C–D (26), C–E (14) has a unique MST. What is the…
- Kruskal's algorithm runs on the weighted undirected graph A–B (20), A–C (3), A–E (8), A–F (6), B–D (10), C–D (1), C–G (16), D–E (25), D–F…
- A binary search tree holds exactly the keys 16, 17, 41, 44, 69, 81, 82, 95. Which ONE of the following sequences can be its PREORDER…
- In the DAG with edges A→D, A→F, C→B, D→B, D→C, D→E, D→F, D→G, E→B, G→E, G→F, how many distinct directed paths are there from A to F, and…
- An undirected graph has edges A–B, A–G, B–E, C–E, C–F, C–G, D–E, D–F, D–G. An ITERATIVE DFS starts with stack [A]; it pops a vertex, skips…