Algorithm Presentation
Algorithm Presentation
Algorithm Presentation
Algorithms
Breadth-First
Search Algorithm
Pseudocode
Advantages and Disadvantages of BFS
Advantages: Disadvantages:
BFS will provide a solution if any solution It requires lots of memory since each level
exists. of the tree must be saved into memory to
If there are more than one solutions for a expand the next level.
given problem, then BFS will provide the BFS needs lots of time if the solution is far
minimal solution which requires the least away from the root node.
number of steps.
Depth-first search is recursive
DFS DFS-depth first search algorithm for traversing a tree or
graph data structure.
DFS uses a stack data structure for its The process of the DFS algorithm is
implementation. similar to the BFS algorithm.
Depth-First Search
Algorithm Pseudocode
Advantages and
Disadvantages of
DFS
Advantages: Disadvantages:
DFS requires very less memory There is the possibility that
as it only needs to store a stack many states keep re-occurring
of the nodes on the path from ,and there is no guarantee of
root node to the current node. finding the solution.
It takes less time to reach to the DFS algorithm goes for deep
goal node than BFS algorithm down searching and
(if it traverses in the right path). sometimes it may go to the
infinite loop.
Sr. Key BFS DFS
No.
Definition BFS, stands for Breadth First DFS, stands for Depth First
1 Search. Search.
Differences between Data structure BFS uses Queue to find the DFS uses Stack to find the
Source BFS is better when target is DFS is better when target is far
3 closer to Source. from source.
Suitablity for As BFS considers all neighbour DFS is more suitable for
decision tree so it is not suitable for decision decision tree. As with one
tree used in puzzle games. decision, we need to traverse
further to augment the
decision. If we reach the
4 conclusion, we won.
Problem on BFS
Problem on
BFS
Problem on DFS
Problem on
DFS