Google News
logo
Artificial Intelligence - Interview Questions
What is the difference between breadth-first and depth-first search algorithms?
Both Breadth-First Search (BFS)  and Depth-First Search (DFS) algorithms are used to search tree or graph data structures.
 
Breadth-first search algorithm :
* It is based on FIFO (first-in, first-out) method.
* It starts from the root node, proceeds through neighboring nodes, and finally moves towards the next level of nodes. Till the arrangement is found and created, it produces one tree at any given moment
* The method strategy gives the shortest path to the solution.
 
 
Depth-first search algorithm :
* It is based on the LIFO (Last-in, Last Out) approach.
* It starts at the root node and searches as far as possible along every branch before it performs backtracking.
* The path is stored in each iteration from root to leaf nodes in a linear fashion with space requirement.
Advertisement