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

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

  1. A. ECDBA
  2. B. ABDCE
  3. C. ACEBD
  4. D. ABCDE

Correct answer: B. ABDCE

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic