GATE Computer ScienceHardGATE CS (PYQ pattern)
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 the vertices c and d?
- A. 27
- B. 18
- C. 9
- D. 12
Correct answer: B. 18
Every s–t path passes through c or d. There are 27 s–t paths in total; the 9 paths that use the edge c→d visit both. So 27 − 9 = 18 visit exactly one. Forgetting the edge c→d gives 27 by double counting.
More Algorithms questions
- 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) +…
- A hash table of size 13 uses double hashing: the probe sequence is (k mod 13 + i·(1 + (k mod 11))) mod 13. Keys 19, 27, 36, 10, 25, 40, 53…