Data Structures & AlgorithmsHardGATE CS · TCS NQT · Product Company SDE

An undirected graph has adjacency lists A:BCEF B:AD C:ADF D:BCF E:A F:ACD. Neighbours are always explored in alphabetical order. Which is the DFS (recursive, pre-order) visiting order starting at A?

  1. A. ABCEFD
  2. B. ABDCFE
  3. C. ABDCEF
  4. D. EFCDBA

Correct answer: B. ABDCFE

DFS goes as deep as possible before backtracking, taking neighbours in alphabetical order, giving ABDCFE.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic