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
I'm quite amazed that nobody has mentioned so far about the difference in results given by DFS
and BFS
.
The main difference between these two algorithms is that BFS returns the shortest path and DFS returns just a path.
So if you want to get the shortest path use BFS
, otherwise consider other pros and cons (memory etc.)