GATE Computer ScienceVery hardGATE CS (PYQ pattern)
Bellman–Ford is run from S on a directed graph with edges S→A 2, A→B 3, B→C −4, C→A 0, C→D 5, D→E 1, E→H 2, S→F 7, F→G −2, S→I 4, I→F 1, J→B 1. For how many vertices is the shortest distance from S equal to −∞?
- A. 3
- B. 4
- C. 6
- D. 7
Correct answer: C. 6
The cycle A→B→C→A has weight 3 − 4 + 0 = −1, so it is a reachable negative cycle. Its vertices A, B, C and everything reachable from them (D, E, H) have distance −∞: that is 6 vertices. F, G and I have finite distances (5, 3, 4) and J is unreachable from S.
More Algorithms questions
- What is the smallest possible value of the largest edge weight on a path from E to D in the graph with edges AB 6, AC 1, AD 5, BC 5, BE 3…
- Kahn's topological sort uses a min-priority queue, so among available vertices the smallest label is always chosen. The DAG has edges 1→3…
- A DAG has edges s→a, s→b, a→b, a→c, a→d, b→c, b→d, c→d, c→e, c→f, d→e, d→f, e→f, e→t, f→t. How many s–t paths pass through exactly one of…
- How many spanning trees of the complete graph K₅ (vertices 1–5) contain neither the edge 1-2 nor the edge 1-3?
- For the pattern P = abcabdabcabcabd, the KMP failure (prefix) function π[i] is the length of the longest proper prefix of P[0..i] that is…
- Boyer–Moore–Horspool searches for P = abcab in T = abcabdabcabcabcabxab (20 characters). The window is compared right to left; after every…