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

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

  1. A. ABDFCE
  2. B. ABCFDE
  3. C. ABDFEC
  4. D. CEFDBA

Correct answer: C. ABDFEC

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic