19 August 2017

Advantages and disadvantages of DFS and BFS

Advantages of Breadth First Search:
  1. Used to find the shortest path between vertices
  2. Always finds optimal solutions.
  3. There is nothing like useless path in BFS,since it searches level by level.
  4. Finds the closest goal in less time
Disadvantages of BFS:
  1. All of the connected vertices must be stored in memory. So consumes more memory
Advantages of Depth First Search:
  1. Consumes less memory
  2. Finds the larger distant element(from source vertex) in less time.
Disadvantages of BFS:
  1. May not find optimal solution to the problem.
  2. May get trapped in searching useless path.