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

