Why did Deep First Search say it suffers from endless cycles?

I have read about DFS and BFS many times, but I have this doubt that has been holding my mind back since ancient times. Many articles mention that DFS can get stuck in endless loops.

As far as I know, this restriction can be easily removed by tracking visited sites. In fact, in all the books I read, this little check is part of DFS.

So why are "infinite loops" referred to as a DFS flaw? Is it just because the original DFS algorithm did not have this check for visited nodes? Please explain.

+7
source share
2 answers

(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

+19
source

A regular DFS algorithm tracks nodes. The local search algorithm does not track conditions and behaves with amnesia. Therefore, I think that the loop mainly refers to an infinite branch (branches with infinite possible states). In this case, DFS simply drops and becomes too focused on one branch.

+3
source

All Articles