top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

BFS vs DFS with example?

+2 votes
596 views

Can someone explain in simple terms with example what is the BFS and what is DFS. In what situation BFS would be more useful then DFS or vice-versa.

posted Nov 30, 2013 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button
BFS vs DFS of What ??? TREE or Graph ??
Its about graph?

1 Answer

0 votes

Comparing BFS and DFS, the big advantage of DFS is that it has much lower memory requirements than BFS, because it’s not necessary to store all of the child pointers at each level. Depending on the data and what you are looking for, either DFS or BFS could be advantageous.

For example, given a family tree if one were looking for someone on the tree who’s still alive, then it would be safe to assume that person would be on the bottom of the tree. This means that a BFS would take a very long time to reach that last level. A DFS, however, would find the goal faster. But, if one were looking for a family member who died a very long time ago, then that person would be closer to the top of the tree. Then, a BFS would usually be faster than a DFS. So, the advantages of either vary depending on the data and what you’re looking for.

answer Jan 13, 2014 by Atul Mishra
...