Data Structures & AlgorithmsModerateTCS NQT · Infosys pattern

An undirected graph has edges A–B, A–C, B–D, C–D, C–E, D–F, E–F, and neighbours are always taken in alphabetical order. What is the DFS order starting from A?

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

Correct answer: A. A B D C E F

A → B → D; D's smallest unvisited neighbour is C → C; C's next unvisited is E → E → F. So A B D C E F. A B C D E F is the BFS order.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic