Wednesday, 17 February 2016

What is the difference between depth-first-search and breadth-first-search?

1. In BFS the root node is expanded first, then all the successors of the root node are expanded, and in next step all the successors of every node are expanded, the process continues till the goal is achived.   while
In DFS we explore the root node and traverse as far as possible from the root node untill the goal is    achived.

2.In BFS the space complexity is more critical as compared to time complexity.   while
In DFS has lesser space complexity, because at a time it needs to store only single path from the root to leaf node.

3.Breadth First Search can be done with the help of queue i.e, FIFO(First In FirstOut).   while
Depth First Search can be done with the help of stack i.e. LIFO(Last In First Out).

4.BFS is slower than DFS.   while
DFS is more faster than BFS.

5.BFS requires more memory compare to DFS.  while
DFS require less memory compare to BFS.

6.BFS is useful in finding shortest path.  while
DFS in not so useful in finding shortest path.


BFS  Example:-


DFS  Example:-

No comments:

Post a Comment