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: F→A (9), D→A (4), E→D (8), C→B (5), D→C (0), E→F (-2), B→F (-1), B→E (5), A→E (0). 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 -2
- B. 4 passes, dist -2
- C. 2 passes, dist -2
- D. 3 passes, dist -2
Correct answer: D. 3 passes, dist -2
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 3 passes change something (then one pass confirms nothing changes). Final distances: A=0, B=13, C=8, D=8, E=0, F=-2.
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 (1), 1→3 (5), 2→1 (1), 2→4 (8), 3→1 (3), 3→2 (9), 4→3 (2). After the…
- A tree on vertices 1–9 has edges 2–1, 3–1, 4–3, 5–2, 6–4, 7–6, 8–6, 9–8. What are its diameter and radius, and which vertex/vertices form…
- Five matrices have dimensions 12×10 , 10×4 , 4×6 , 6×6 , 6×8. What is the minimum number of scalar multiplications needed to compute their…
- An undirected graph has edges A–D, A–F, A–G, B–C, B–F, C–D, C–E, E–G, F–G. An ITERATIVE DFS starts with stack [A]; it pops a vertex, skips…
- What is the length of the longest common subsequence of ONTOLOGY and TOPOLOGY, and how many DISTINCT longest common subsequences (as…
- Edit distance between MARTIAN and COMPILER where insert and delete cost 1 each but a substitution costs 2: what is the minimum total cost?