Consider the following graph.

Among the following sequences
I. a b e g h f
II. a b f e h g
III. a b f h g e
IV. a f g h b e Which are depth first traversals of the above graph?
Pick an option to check yourself, or open the answer below.
Show answer & explanation
Correct answer: D. I, III, and IV only
Explanation
Edges: a–b, a–e, a–f, b–e, b–f, b–h, f–h, f–g, h–g, e–g. I (a b e g h f) and III (a b f h g e) and IV (a f g h b e) each move to an unvisited neighbour of the latest vertex. In II, after a b f the next vertex e is not adjacent to f while f still has unvisited neighbours, so II is not a DFS.
More Data Structures and Algorithms questions
- Which of the given options provides the increasing order of asymptotic complexity of f1, f2, f3 f4 functions and ? f1(n) = 2n A. f2(n) = n3…
- A hash function h(key) = key mod 7 with linear probing is used to insert the keys 44, 45, 79, 55, 91, 18, 63 into a table indexed 0 to 6. W…
- Match each graph algorithm with its time complexity (n vertices, m edges). List I: A. Bellman-Ford, B. Kruskal's algorithm, C. Floyd-Warsha…
- The reverse Polish notation of the infix expression [A * {B + C * (D + E)}] / {F * (G + H)} is
- With preconditions a > 1 and a < b (no overflow): int x = 0; int p = 1; while (p < b) { p = p * a; x = x + 1; } When the loop ends, x in te…
- A complete -ary tree is a tree in which each n I node has children or no children. Let be the L number of internal nodes and be the number…