Data Structures & AlgorithmsVery hardGATE CS · Product-company placement
DFS runs on the directed graph with adjacency lists A: BDF; B: FG; C: ABE; D: G; E: –; F: D; G: A, 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 5, back 1, forward 2, cross 3
- B. tree 5, back 1, forward 3, cross 2
- C. tree 5, back 1, forward 1, cross 4
- D. tree 5, back 2, forward 3, cross 1
Correct answer: B. tree 5, back 1, forward 3, cross 2
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 5, back 1, forward 3, cross 2.
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
- The directed graph A→C (5), A→D (4), A→E (7), B→D (2), C→B (4), C→D (1), D→E (7), E→C (-5) has one negative edge but no negative cycle…
- A binary min-heap is stored in a 0-indexed array [2, 19, 33, 58, 25, 35, 53]. Perform, in order: insert 36, insert 8, delete-min…
- Keys 78, 77, 48, 42, 39, 27, 67, 23, 57 are inserted in that order into an empty AVL tree. What is the preorder traversal of the final tree?
- Lectures occupy half-open intervals [start, end): [0, 3), [0, 7), [3, 7), [4, 12), [8, 12), [10, 16), [12, 18), [19, 27). A lecture ending…
- Kruskal's algorithm runs on the weighted undirected graph A–D (13), A–F (22), B–F (5), B–G (19), C–D (12), C–G (17), D–F (27), D–G (20)…
- A binary min-heap is stored in a 0-indexed array [4, 15, 11, 32, 56, 47, 48]. Perform, in order: insert 28, insert 38, insert 19…