Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which Procedure we can use for Maze exploration BFS or DFS

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

like image 663
Atinesh Avatar asked Nov 25 '13 11:11

Atinesh


1 Answers

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.)

like image 187
pkacprzak Avatar answered Oct 14 '22 06:10

pkacprzak