Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div 2 B
Bellman–Ford is run from source I on the directed graph whose arcs (weights in brackets) are listed in the order they are relaxed: O→I (9), V→G (4), G→O (4), V→O (6), O→G (8), I→V (8). 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. 3
- B. 6
- C. 4
- D. 2
Correct answer: A. 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 counter starts at 1. Each step, you may add 1, add 2, or double the counter. Each step must stay at or below 12. Two sequences of steps…
- Consider this recursive function: python def f(n): if n <= 1: return f(n - 2) if n % 3 == 0: f(n - 2) How many times is f called in total…
- An undirected graph has the vertices J, K, M, O, P, Y and the edges P–M, P–Y, P–O, P–K, P–J, M–Y, M–O, Y–K, O–K. What is its chromatic…
- A directed graph has the vertices B, F, I, S and the arcs I→F, I→S, F→I, F→B, S→I, S→F, S→B, B→F, B→S. Count the directed Hamiltonian…
- An undirected graph has the vertices L, O, Q, Y, Z and the edges L–Z, O–Z, O–Y, Q–O, Q–Y, L–Y, L–Q, Y–Z. What is the minimum number of…
- An undirected graph has the vertices C, E, L, M, T and the edges L–E, L–T, M–C, E–C, C–T. In how many ways can each vertex be given one of…