Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2 B
Bellman–Ford is run from source P on the directed graph whose arcs (weights in brackets) are listed in the order they are relaxed: Z→S (7), Y→R (2), Z→R (1), R→P (8), Y→Z (1), S→Y (8), Z→P (4), P→Z (6), P→S (9), S→R (5), P→R (1). 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. 11
- B. 2
- C. 4
- D. 3
Correct answer: D. 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 directed graph has the vertices F, J, N, P, R, Z and the arcs P→F, P→Z, P→N, J→N, R→P, F→P, F→R, Z→P, Z→N, N→F, N→Z. How many strongly…
- Grid with 4 rows and 4 columns (top to bottom). A cell marked G is a gate; '.' is a normal cell: ...G .GGG GG.G G... Each step, which is a…
- A connected undirected graph has the vertices A, B, E, J, M and weighted edges (weights in brackets): M–E (8), A–E (17), M–B (10), A–B…
- An undirected graph has the vertices B, D, O, Q, T, X and the edges D–Q, X–D, B–D, X–Q, O–D, X–T, B–Q, D–T, X–O. What is the minimum…
- A directed acyclic graph has the vertices A, E, F, J, L, N and the arcs F→N, F→E, F→J, F→A, L→E, N→E, E→A, J→A. Two players alternately…
- A bipartite graph has left side P1, P2, P3, P4 and right side Q1, Q2, Q3, Q4, Q5, with edges P1–Q1, P4–Q1, P1–Q2, P1–Q5, P4–Q5, P2–Q5…