Data Structures & AlgorithmsHardIBM · Deloitte pattern

An undirected graph has adjacency lists (neighbours visited in alphabetical order) A: [D, F]; B: [C, F]; C: [B, E]; D: [A, E]; E: [C, D]; F: [A, B]. What is the (recursive) DFS traversal order starting from A?

  1. A. A, B, C, D, E, F
  2. B. F, B, C, E, D, A
  3. C. A, D, E, C, B, F
  4. D. A, D, F, E, B, C

Correct answer: C. A, D, E, C, B, F

Recursive DFS from A immediately recurses into the first unvisited neighbour before trying the next one, diving as deep as possible before backtracking, giving A, D, E, C, B, F. BFS from the same start would instead explore level by level, giving A, D, F, E, B, C.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic