Translate

Visit to www.mrmcse.com

10 March 2018

Differentiate between BFS and DFS



BFS
DFS
(i) BFS is vertex based algorithm.
(i) DFS is an edge based algorithm.
(ii) BFS is optimal algorithm.
(ii) DFS is not optimal algorithm.
(iii) Queue data structure is used in BFS.
(iii) DFS uses stack or recursion.
(iv) Memory space is not efficiently utilized in BFS.
(iv) Memory space is efficiently utilized in DFS.
(v) BFS constructs wide and short tree.
(v) DFS constructs narrow and long trees.
(vi) BFS is slower and require more memory.
(vi) DFS is faster and require less memory.
(vii) BFS visit nodes level by level in Graph.
(vii) DFS visit nodes of graph depth wide. It visits nodes until reach doesn’t reach a leaf or node which doesn’t have non-visited nodes.
(viii) Some applications:
  • Finding all connected components in a graph.
  • Finding the shortest path between two nodes.
  • Testing a graph for bipartitions.

(viii) Some application:
  • Topological sorting
  • Finding connected components
  • Solving puzzles such as maze
  • Finding strongly connected components



No comments:

Post a Comment