GATE Computer ScienceHardGATE CS (PYQ pattern)
Bellman–Ford is run from A on a 6-vertex graph with directed edges relaxed in this fixed order in every pass: E→F 2, D→E 3, C→D 2, B→C 4, A→B 1, A→F 20. In how many passes does at least one distance label change?
- A. 3
- B. 4
- C. 5
- D. 6
Correct answer: C. 5
Each pass only extends the correct prefix of the chain A→B→C→D→E→F by one edge, because the edges appear in reverse path order: B, C, D, E and F are fixed in passes 1, 2, 3, 4 and 5 respectively. A sixth pass changes nothing, and V − 1 = 5 is the worst case, achieved here.
More Algorithms questions
- A weighted undirected graph has vertices A–F and edges AB 1, BC 1, CA 1, CD 2, DE 2, EC 2, EF 3, FD 3, AF 7. How many distinct minimum…
- A weighted undirected graph on vertices A–G has edges AB 4, AC 8, BC 2, BD 5, CD 9, CE 10, DE 3, DF 11, EF 4, EG 7, FG 5, BG 20. Its MST…
- How many spanning trees does the wheel graph W₅ have (a hub joined to every vertex of a 5-cycle: 6 vertices, 10 edges)?
- How many spanning trees does the 3-dimensional hypercube Q₃ (8 vertices, 12 edges) have?
- A DAG on vertices 1–8 has edges 1→2, 1→3, 2→4, 3→4, 4→5, 4→6, 5→7, 6→7, 3→8, 8→7. How many different topological orderings does it have?
- A DFS on a directed graph processes vertices in alphabetical order and each adjacency list in alphabetical order. Edges: A→B, A→C, A→E…