Data Structures & AlgorithmsModerateGATE CS · ICPC regional
Bellman–Ford is run from source C on the directed graph whose arcs (weights in brackets) are listed in the order they are relaxed: C→F (4), Q→A (4), A→K (3), C→K (8), F→Q (8), K→F (3), C→A (4), Q→K (1), K→C (5), F→C (8), K→A (6). 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. 4
- B. 11
- C. 3
- D. 2
Correct answer: C. 3
The last pass changes no distance, so it is counted; the passes before it changed something, 2 of them. The bound n − 1 = 4 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 flow network has source S and sink T, with directed arcs and capacities in brackets: S→A (5), S→D (9), S→T (7), E→C (2), E→D (2), E→T…
- An undirected graph has the vertices D, L, N, R, X, Z and the edges N–L, Z–X, X–L, Z–D, L–R, Z–L, Z–N. How many simple cycles does it…
- An undirected graph has the vertices A, J, L, Q, W, X, Y and the edges L–J, L–X, L–W, L–A, Q–X, Q–A, J–Y, Y–W. What is the size of a…
- A pile holds p stones. In one move a player removes exactly s stones, where s is one of {1, 2, 4} and s ≤ the pile size. The player who…
- An undirected graph has the vertices F, J, K, M, S, T, V, X and the edges J–V, J–X, J–F, J–M, J–K, V–F, V–S, X–F, X–M, X–K, F–K, S–M. What…
- An undirected graph has the vertices A, J, K, L, O, Q, X, Y and the edges J–Q, J–Y, J–A, J–O, Q–L, Q–X, K–L, K–O. What is the size of a…