Data Structures & AlgorithmsVery hardGATE CS
DFS runs on the directed graph with adjacency lists A: BDE; B: E; C: AE; D: BF; E: –; F: BCG; 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 6, back 1, forward 1, cross 3
- B. tree 6, back 1, forward 3, cross 1
- C. tree 6, back 1, forward 2, cross 2
- D. tree 6, back 3, forward 1, cross 1
Correct answer: A. tree 6, back 1, forward 1, 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 6, back 1, forward 1, 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
- The weighted undirected graph A–E (19), A–F (20), B–F (2), C–D (25), C–E (10), C–F (7), D–E (18), D–F (8) has a unique MST. What is the…
- A complete binary tree (array form, all levels full except possibly the last, which is filled from the left) has 91 nodes. How many leaves…
- What is the minimum number of edges m such that EVERY simple undirected graph with 13 vertices and m edges is guaranteed to be connected?
- Keys 51, 83, 75, 67, 42, 93, 22, 21, 38, 81 are inserted in order into an empty AVL tree. Counting a double rotation as two single…
- In how many different ways can 'aaaaaa' be split into a sequence of words from the dictionary {a, aa, aaa} (every character used, order…
- 0/1 knapsack with capacity 14: items (weight, value) = (7, 23), (4, 12), (5, 8), (4, 12), (6, 34). What is the maximum total value?