这过程中,我们可以使用迷宫探索BFS或DFS

编程入门 行业动态 更新时间:2024-10-05 09:28:37
本文介绍了这过程中,我们可以使用迷宫探索BFS或DFS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我知道我们可以使用DFS的迷宫探索。但我认为,我们还可以使用BFS的迷宫探索。我有点困惑在这里,因为大部分我读过的书和文章都使用DFS这个问题。 我认为这是在最佳案例 DFS的时间复杂度会比BFS更好。但一般和最坏 案例的时间复杂度将是相同的两个BFS和放大器; DFS和这就是为什么我们preFER DFS在BFS。 我说得对还是我有一些误解。

I know we can use DFS for maze exploration. But I think we can also use BFS for maze exploration. I'm little bit confused here because most of the books and articles that I've read had used DFS for this problem. What I think is that the Best Case time complexity of DFS will be better as compared to BFS. But Average and Worst Case time complexity will be same for both BFS & DFS and thats why we prefer DFS over BFS. Am I right or I'm having some misconception

推荐答案

我很惊讶,没有人提到迄今为止关于通过 DFS 给出结果的差异, BFS 。

I'm quite amazed that nobody has mentioned so far about the difference in results given by DFS and BFS.

这两种算法的主要区别在于, BFS返回的最短路径和 DFS只返回路径

The main difference between these two algorithms is that BFS returns the shortest path and DFS returns just a path.

所以,如果你想获得的最短路径使用 BFS ,否则考虑其他的优点和缺点(内存等)

So if you want to get the shortest path use BFS, otherwise consider other pros and cons (memory etc.)

更多推荐

这过程中,我们可以使用迷宫探索BFS或DFS

本文发布于:2023-11-29 15:30:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1646802.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:可以使用   迷宫   过程中   DFS   BFS

发布评论

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

>www.elefans.com

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