Skip to content

UGC NET CS 2022Data Structures and Algorithms › Graph AlgorithmsVerified

UGC NET CS 2022 PYQ: Consider the following graph : For the graph; the following sequences of depth first search (DFS) are given…

Consider the following graph :

Graph


For the graph; the following sequences of depth first search (DFS) are given

  1. $\text{abcghf}$
  2. $\text{abfchg}$
  3. $\text{abfhgc}$
  4. $\text{afghbc}$

Which of the following is correct?

  1. A
    $(\text{I}), (\text{II})$ $\text{and}$ $(\text{IV})$ only
  2. B
    $(\text{I}), (\text{II}), (\text{III})$ $\text{and}$ $(\text{IV})$
  3. C
    $(\text{II})$, $(\mathrm{III})$ $\text{and}$ $(\mathrm{IV})$ only
  4. D
    $(\text{I}), (\text{III})$ $\text{and}$ $(\text{IV})$ only
    Correct answer

Answer

(D) $(\text{I}), (\text{III})$ $\text{and}$ $(\text{IV})$ only

Approach

From the graph, adjacency is: a–{b,c,f}, b–{a,c,f,h}, c–{a,b,g}, f–{a,b,h,g}, g–{c,f,h}, h–{b,f,g}. A DFS sequence is valid iff each consecutive pair is an edge and it respects DFS order (each new vertex is a neighbor of the current one, backtracking allowed).

(I) a b c g h f: a–b, b–c, c–g, g–h, h–f — all are edges, valid.
(II) a b f c h g: after b→f, the next vertex c is NOT adjacent to f (f's neighbors are a,b,h,g), so invalid.
(III) a b f h g c: a–b, b–f, f–h, h–g, g–c — all edges, valid.
(IV) a f g h b c: a–f, f–g, g–h, h–b, b–c — all edges, valid.

Thus (I), (III), (IV) are correct DFS sequences, giving option D. (II) fails because f and c are non-adjacent.

Reviewed by UGC IQ Editorial Team.