Data Structures & AlgorithmsHardICPC regional · GATE CS top band
Directed weighted graph on vertices A, B, C, D, E, F with edges listed in this exact order: D→B (2); A→E (7); A→C (3); D→C (-1); B→A (-2); D→F (2); B→D (6); E→B (4). Bellman–Ford from A makes passes over the edge list in that order, relaxing in place (each edge is tried once per pass). Counting the passes from the first, how many passes change at least one distance?
- A. 4
- B. 8
- C. 5
- D. 3
Correct answer: D. 3
The distances settle after 3 passes that change something; one more pass is needed only to confirm nothing changes, and that final pass is not counted.
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
- Connected undirected graph on vertices A, B, C, D, E, F, G, H with edges A–D (1), B–F (1), B–G (1), B–H (1), C–H (1), D–G (1), E–H (1)…
- Array A = [3, 1, 7, 5, 2, 5, 4, 6, 1] (indices 0 to 8). Count the non-empty subsets of positions (each position used at most once, subsets…
- Connected undirected graph on vertices A, B, C, D, E, F, G, H with edges A–B (1), A–E (1), A–F (1), B–E (1), C–E (1), D–E (1), E–G (1)…
- Undirected weighted graph on vertices A, B, C, D with edges A–B (1), A–C (1), A–D (1), B–C (3), B–D (2), C–D (1). How many distinct…
- Directed weighted graph on vertices B, F, C, A, D (source B, target D) with edges: B→F (5); B→C (6); C→F (-3); F→D (1); C→D (4); B→D (18)…
- Coins of denominations [12, 9, 7, 2] are available in unlimited quantity. What is the minimum number of coins needed to pay exactly 16?…