问题描述
我知道我们可以使用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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!