Breadth-First Search (BFS) vs Depth First Search (DFS)
Breadth-First Search and Depth First Search are a couple of searching algorithms at the basic level which represent an easy procedure for solving a problem in the real world. It is mainly a traditional way for modern types of searching.
Breadth-First Search Algorithm
This Breadth-First Search Algorithm algorithm is also known as level order traversal. The Queue data structure is used for the searching of Breadth-First Search traversal. When the BFS algorithm is used on a graph for calculation any node present in the program is known as a root node.
BFS algorithm is known as a traversal mechanism in which all the nodes of the same level are explored first, and then it is moved to the next level to explore. It is also known as level by level or generation by generation.
Data Structure used: Queue data structure
Depth-First Search Algorithm
It is an edge-based technique because the vertices along the edge are explored first from the starting to the end node. Depth-first searching can be used to simply explore an entire graph or can be used to find a specific path between two nodes. DFS algorithm is a traversal mechanism where the traversal starts from the root node and afterward, explores the nodes as far as possible until we reach the node that has no unvisited adjacent nodes.
Data Structure used : Stack data structure
Therefore we are clear that the DFS algorithm is very simple and has a fast computational time. But, often the DF search can be useless as it goes deep in search of nodes and if none of the nodes are found the computation can be a waste of time and resources.
Below the given link is the computation of the BFS and DFS algorithms in the Github: https://github.com/thisura1997/Krish-FullStack-Training/tree/BFS_DFS-Codings
References:
[1] Breadth-First Search VS. Depth First Search (with Pictures!) [2022], https://medium.com/geekculture/breadth-first-search-vs-depth-first-search-with-pictures-e1ad53248009
[2] Youtube: Krishantha Dinesh [2022], https://www.youtube.com/watch?v=aMCI4AqVUug&list=RDCMUCi5H-ZH48t5tjSax636Dn2A&index=1