GATE Computer ScienceHardGATE CS (PYQ pattern)
A topological order of the DAG with edges A→B, A→C, B→D, C→D, C→E, D→F, E→F, E→G, G→F, H→C, H→G is produced by running DFS (roots in alphabetical order, each adjacency list in the order written above) and listing vertices in decreasing finishing time. Which vertex is fourth in this order?
- A. E
- B. B
- C. D
- D. G
Correct answer: A. E
The DFS finishes in the order F, D, B, G, E, C, A, H, so the decreasing-finish list is H, A, C, E, G, B, D, F. The fourth vertex is E.
More Algorithms questions
- A directed graph has edges s→a, s→b, s→c, s→d, a→m, b→m, c→m, m→p, m→q, m→r, p→t, q→t, r→t, d→t. Let E be the maximum number of…
- Men m0–m3 and women w0–w3 have the preference lists (best first) m0: w2 w0 w1 w3; m1: w0 w1 w3 w2; m2: w1 w2 w0 w3; m3: w2 w3 w1 w0; w0…
- Union by rank without path compression is performed (ties: the root of the second argument is attached below the root of the first) on…
- Graham scan or Andrew's monotone chain is used on the points (0,0), (4,1), (2,2), (6,3), (3,5), (8,6), (5,7), (1,8), (7,3), (4,4), (2,6)…
- A Fenwick tree (binary indexed tree) over positions 1–100 performs update(i) by visiting i, then i + (i & −i), and so on while the index…
- The Z-array of a string s has Z[i] = length of the longest common prefix of s and s[i..]. (Z[0] is taken as 0.) What is the sum of all Z…