为什么说深度优先搜索会遭受无限循环的困扰?

编程入门 行业动态 更新时间:2024-10-06 12:35:26
本文介绍了为什么说深度优先搜索会遭受无限循环的困扰?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经阅读了有关 DFS 和 BFS 很多次,但我对此疑问一直困扰不已。在很多文章中都提到DFS可能陷入无限循环。

I have read about DFS and BFS many times but I have this doubt lingering my mind since long. In a lot of articles it is mentioned that DFS can get stuck in infinite loops.

据我所知,通过跟踪访问者可以轻松地消除此限制。节点。实际上,在我读过的所有书中,这张小支票都是DFS的一部分。

As far as I know, this limitation can easily be removed by keeping track of the visited nodes. In fact, in all the books that I have read, this little check is a part of DFS.

那么为什么提到无限循环是DFS的缺点?仅仅是因为原始DFS算法没有对访问的节点进行此检查吗?请解释。

So why are 'infinite loops' mentioned as a disadvantage of DFS? Is it just because the original DFS algorithm did not have this check for visited nodes? Please explain.

推荐答案

(1)在图搜索算法中[在AI上经常使用],DFS的主要优势是 space效率。这是它在BFS上的主要优势。但是,如果跟踪访问的节点,则会失去这一优势,因为您需要将所有访问的节点存储在内存中。不要忘了访问的节点的大小会随着时间的推移而急剧增加,对于非常大/无限的图-可能不适合存储在内存中。

(1) In graph search algorithms [used frequently on AI], DFS's main advantage is space efficiency. It is its main advantage on BFS. However, if you keep track of visited nodes, you lose this advantage, since you need to store all visited nodes in memory. Don't forget the size of visited nodes increases drastically over time, and for very large/infinite graphs - might not fit in memory.

(2)有时DFS可以是在无限分支中(在无限图中)。无限分支是一个没有结束的分支[总是有更多的儿子],并且也没有将您带到目标节点,因此对于DFS,您可能会无限期地扩展该分支,并错过好的分支,

(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 get you to your target node, so for DFS, you might keep expanding this branch inifinitely, and 'miss' the good branch, that leads to the target node.

奖金: 您可以克服DFS中的这一缺陷,同时保持相对较小的比例通过结合使用DFS和BFS来增加内存大小:迭代加深DFS

更多推荐

为什么说深度优先搜索会遭受无限循环的困扰?

本文发布于:2023-11-29 02:03:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1644850.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:困扰   深度

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!