Data Structures & AlgorithmsVery hardGATE CS
DFS runs on the directed graph with adjacency lists A: D; B: CF; C: AEG; D: –; E: ABG; F: D; G: F, 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 0, cross 5
- D. tree 5, back 3, forward 2, cross 1
Correct answer: A. tree 5, back 1, forward 2, cross 3
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 2, cross 3.
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
- Symbols occur with frequencies 24, 26, 33, 34, 35, 38. How many bits does an optimal (Huffman) prefix code need for the whole message, and…
- A binary search tree holds exactly the keys 27, 34, 63, 64, 72, 73, 95, 99. Which ONE of the following can be its POSTORDER traversal?
- Five matrices have dimensions 5×5 , 5×5 , 5×15 , 15×4 , 4×3. What is the minimum number of scalar multiplications needed to compute their…
- The directed graph A→B (4), A→C (5), A→E (3), B→D (6), B→E (-3), C→E (7), D→C (1), E→D (2) has one negative edge but no negative cycle…
- Dijkstra's algorithm runs from A on the directed graph A→C (15), A→D (3), B→E (4), B→F (12), C→B (12), C→E (1), D→B (2), D→C (9), E→A…
- Heap sort (ascending) is run on [44, 9, 47, 27, 1, 46, 30, 10]: build a max-heap bottom-up, then repeatedly swap the root with the last…