Data Structures & AlgorithmsHardICPC regional · GATE CS top band
Directed weighted graph on vertices A, B, C, D, E with edges listed in this exact order: A→B (6); E→A (4); C→D (5); B→E (5); B→C (4); A→D (7); E→B (0); B→D (5); A→C (0). 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. 9
- C. 2
- D. 3
Correct answer: C. 2
The distances settle after 2 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
- Distinct words ['ca', 'b', 'bac', 'a', 'c', 'bbbb'] are inserted into an empty trie (one node per character, shared prefixes sharing…
- A chain of 6 matrices M1 to M6 has dimensions given by the sequence p = [16, 18, 7, 19, 14, 15, 7], where Mi has size p[i−1] × p[i]…
- Connected undirected weighted graph on vertices A, B, C, D, E with edges A–B (12), A–C (16), A–D (15), B–C (2), B–D (20), B–E (17), C–E…
- Directed weighted graph on vertices A, B, C, D, E with edges (u→v, w): E→B (1); A→E (3); C→E (3); C→B (8); D→C (7); D→A (9); C→D (5); D→E…
- Bipartite graph with left side {A, B, C}, right side {D, E, F, G} and edges B–D, B–G, C–D, C–E, C–F. What is the size of a maximum…
- Rooted tree with root 0 and vertices 0 to 9; the edges are 0–1, 1–2, 2–3, 2–4, 2–5, 0–6, 2–7, 7–8, 3–9 (parent–child). Every edge has…