GATE Computer ScienceHardGATE CS (PYQ pattern)
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, 2→3, 2→4, 3→5, 4→5, 6→2, 6→7, 7→4, 5→8, 1→8. Which vertex is the fifth in the output order?
- A. 7
- B. 3
- C. 4
- D. 5
Correct answer: A. 7
The output is 1, 6, 2, 3, 7, 4, 5, 8: vertex 7 only becomes available after 6, and the min-queue prefers 2 and 3 before 7. The fifth vertex is 7.
More Algorithms questions
- 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…
- Rabin–Karp searches for P = 26 in T = 3141592653589793 using base 10 and modulus 11 on 2-digit windows. How many spurious hits (hash equal…
- Keys 10, 20, 30, …, 100 are inserted in this order into an empty hash table of size 10 with h(k) = k mod 10 and quadratic probing (h(k) +…