Data Structures & AlgorithmsHardGATE CS · ICPC regional
Bellman–Ford is run from source X on the directed graph whose arcs (weights in brackets) are listed in the order they are relaxed: F→I (8), X→F (9), T→F (3), F→T (1), I→T (3), I→X (2), I→F (9), X→I (6), T→I (8), F→X (2). One pass relaxes every arc once, in the listed order. Passes are repeated until a complete pass changes no distance. Counting the final pass that changes nothing, how many passes run in total?
- A. 2
- B. 3
- C. 4
- D. 10
Correct answer: B. 3
The last pass changes no distance, so it is counted; the passes before it changed something, 2 of them. The bound n − 1 = 3 counts only the passes needed in the worst case.
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 tree has the vertices C, E, G, K, N, S, T, V, Z and the edges T–K, K–E, K–V, K–S, S–N, N–C, C–G, G–Z. A centroid is a vertex whose…
- A grid has 3 rows and 3 columns with these values (top to bottom): 787 591 837 A path moves between side-adjacent cells (up, down, left or…
- Consider this function: python def g(n): if n < 3: return n if n % 2 == 0: return g(n - 3) + g(n - 2) return g(n - 1) - 1 What value does…
- Consider this recursive function: python def f(n): if n <= 1: return f(n - 1) if n % 2 == 0: f(n - 2) How many times is f called in total…
- A bipartite graph has left side P1, P2, P3, P4 and right side Q1, Q2, Q3, Q4, with edges P1–Q2, P1–Q3, P1–Q1, P2–Q3. What is the size of a…
- A tree has the vertices A, C, D, F, G, M, P, S, X, Y and the edges A–M, A–S, M–Y, A–F, M–D, D–X, Y–C, F–G, S–P. A set D dominates the tree…