Data Structures & AlgorithmsHardGATE CS · ICPC regional · Product Company SDE

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

  1. A. ABCDFE
  2. B. FEDCBA
  3. C. ABCDEF
  4. D. AFDECB

Correct answer: C. ABCDEF

Alphabetical neighbour order. DFS goes as deep as possible before backtracking giving ABCDEF.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic