Breadth First Search Vs Depth First Search

BFS :

  1. It starts from the root node and continue to the next level and visit all the nodes from left to right. After that it will start from the next level.
  2. Its slower than DFS
  3. It requires more memory as it needs to visit all the nodes
  4. Useful in finding the shortest path, Connectivity

DFS :

  1. It starts from the root node and continue/follow the branches of the tree until it reaches the leaf node. If the leaf node is found, then continue with the nearest ancestor
  2. It requires less memory as compared to BFS
  3. Its faster than BFS
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s