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: B→C (-3); D→A (-1); D→E (-2); A→E (6); B→A (-2); E→B (5). 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. 2
- B. 6
- C. 4
- D. 3
Correct answer: A. 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 ['ba', 'c', 'b', 'ca', 'bc', 'aac'] are inserted into an empty trie (one node per character, shared prefixes share nodes…
- Undirected simple graph on vertices A, B, C, D, E, F, G with edges A–D (1), B–C (1), B–E (1), C–D (1), C–E (1), D–E (1), D–G (1), E–G (1)…
- Directed acyclic graph on vertices A, B, C, D, E, F, G (edges go from earlier to later letters) with weights A→C (4), A→F (1), B→D (2)…
- Directed graph on vertices A, B, C, D, E, F with edges F→D, C→F, A→D, A→C, F→E, F→C, B→E (no weights). What is the number of vertices in…
- Undirected weighted graph on vertices A, B, C, D with edges A–B (3), A–C (2), A–D (1), B–C (1), B–D (2). How many distinct minimum…
- Weighted tree on vertices 0 to 8 with edges 0–1 (6), 1–2 (7), 0–3 (8), 0–4 (1), 0–5 (1), 5–6 (6), 2–7 (2), 4–8 (2). What is the largest…