Breadth First Search:BFS stands for Breadth First Search is a vertex-based technique for finding the shortest path in the graph. It uses a Queue data structure that follows first in first out. In BFS, one vertex is selected at a time when it is visited and marked then its adjacent are visited and stored in the queue. It is slower than DFS.
*BFS stands for Breadth First Search.
*BFS(Breadth First Search) uses Queue data structure for finding the shortest path.
*BFS can be used to find single source shortest path in an unweighted graph, because in BFS, we reach a vertex with minimum number of edges from a source vertex.
*BFS is more suitable for searching vertices which are closer to the given source.
*BFS considers all neighbors first and therefore not suitable for decision making trees used in games or puzzles.
*The Time complexity of BFS is O(V + E) when Adjacency List is used and O(V^2) when Adjacency Matrix is used, where V stands for vertices and E stands for edges.
*BFS is used in various application such as bipartite graph, and shortest path etc.
* BFS requires more memory.
Depth First Search:
DFS stands for Depth First Search is an edge-based technique. It uses the Stack data structure and performs two stages, first visited vertices are pushed into the stack, and second if there are no vertices then visited vertices are popped.
*DFS stands for Depth First Search.
*DFS(Depth First Search) uses Stack data structure.
*In DFS, we might traverse through more edges to reach a destination vertex from a source.
*DFS is more suitable when there are solutions away from source.
*DFS is more suitable for game or puzzle problems. We make a decision, then explore all paths through this decision. And if this decision leads to win situation, we stop.
*The Time complexity of DFS is also O(V + E) when Adjacency List is used and O(V^2) when Adjacency Matrix is used, where V stands for vertices and E stands for edges.
*DFS is used in various application such as acyclic graph and topological order etc.
*DFS requires less memory.