(1) In graph search algorithms [often used for AI], the main advantage of DFS is space efficiency . This is his main advantage in BFS. However , if you track visited sites, you lose this advantage , since you need to store all visited sites in memory. Do not forget that the size of the visited nodes increases sharply over time, and for very large / endless graphs - it may not fit in memory.
(2) Sometimes DFS can be in an infinite branch [in infinite graphs]. An infinite branch is a branch that does not end [always has โmore sonsโ], and also does not fall into your target node, so for DFS you can continue to expand this branch endlessly and โskipโ the good branch that leads to the target node.
Bonus:
You can overcome this drawback in DFS by saving a relatively small amount of memory using a combination of DFS and BFS: Iterative deepening DFS
amit
source share