When To Use DFS
A few pointers on preferring DFS:
- If there's a large branching factor (wide) but limited depth.
DFS
is more space-efficient than BFS.- If the tree is very wide,
BFS
will likely be incredibly memory inefficient, soDFS
could be better. - If you need to detect a cycle.