In interviews, should you start with BFS or DFS?

Pros of DFS:

  • easier to write

Pros of BFS:

  • usually more efficient (time wise, but not affecting big O)

I ask this question because in one interview, I started with BFS and turns out that was actually worse in big O space than DFS. So I wasted time.

Even if you have feeling that BFS may be slightly more time efficient, should you do DFS just to ensure a working solution?

Comments (1)