All mock tests are FREE till 31 December — register to save your progress
Unit 7 · Data Structures and Algorithms Paper 2 CS · September 2022

Consider the following undirected graph with vertices a, b, c, f, g, h and edges:
a–b, a–c, a–f, b–c, b–f, b–h, c–g, f–g, f–h, g–h
The following depth-first search (DFS) sequences are given:
(A) abcghf
(B) abfchg
(C) abfhgc
(D) afghbc
Which of the following is correct?

Pick an option to check yourself, or open the answer below.

Show answer & explanation

Correct answer: D. (A), (C) and (D) only

Explanation

(A) a-b-c-g-h-f, (C) a-b-f-h-g-c and (D) a-f-g-h-b-c follow edges and backtrack correctly. In (B), after a-b-f the DFS must go to an unvisited neighbour of f (g or h); c is not adjacent to f.

More Data Structures and Algorithms questions