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

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

  1. A. ABCED
  2. B. AECDB
  3. C. ECDBA
  4. D. ABDCE

Correct answer: D. 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