Data Structures & AlgorithmsVery hardGATE CS · Product-company placement
DFS runs on the directed graph with adjacency lists A: BG; B: FG; C: AEFG; D: C; E: A; F: A; G: –, starting at A, scanning lists in the order shown and restarting from the alphabetically first unvisited vertex. How are the 11 edges classified?
- A. tree 4, back 1, forward 5, cross 1
- B. tree 4, back 1, forward 0, cross 6
- C. tree 4, back 1, forward 1, cross 5
- D. tree 4, back 5, forward 1, cross 1
Correct answer: C. tree 4, back 1, forward 1, cross 5
An edge to a grey (unfinished) vertex is a back edge; to a finished vertex it is forward if that vertex is a descendant (discovered later), otherwise cross. Timestamps give tree 4, back 1, forward 1, cross 5.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- A tree on vertices 1–8 has edges 2–1, 3–2, 4–2, 5–2, 6–2, 7–4, 8–3. What is the sum of the distances (in edges) over all unordered pairs…
- The weighted undirected graph A–B (1), A–C (3), A–D (5), B–D (3), B–E (6), C–D (3), D–E (6) has repeated weights. How many different…
- A DAG on vertices A–G has edges A→C, A→D, A→E, E→B, E→C, E→F, G→E, G→F. What order does Kahn's algorithm that always removes the…
- DFS on the directed graph with adjacency lists A: CDE; B: FG; C: –; D: G; E: FG; F: AG; G: – starts at A (scanning lists in the order…
- Keys 94, 18, 63, 88, 99, 54, 31 inserted in this order build a BST. How many of the 7! orderings of these same 7 keys, inserted into an…
- Unit-time jobs (deadline, profit): J1 (3, 69), J2 (2, 89), J3 (1, 26), J4 (1, 68), J5 (2, 10), J6 (1, 83), J7 (4, 52). One job runs at a…