Depth First Search (DFS)
Depth First Search (DFS) algorithm traverses a graph in a depthward motion and uses a stack data structure to remember to get the next vertex to start a search when a dead end occurs in any iteration.
Breadth First Search (BFS)
Difference between BFS and DFS
Breadth-First Search (BFS) | Depth First Search(DFS) |
BFS stands for Breadth-First Search. | DFS stands for Depth First Search. |
BFS uses Queue Data structure to keep track of the next location to visit. | DFS uses Stack Data structure to keep track of the next location to visit. |
BFS is better when a target is closer to the Source. | DFS is better when a target is far from the source. |
BFS requires more memory as compare to DFS. | DFS requires less memory as compare to BFS. |
BFS does not require backtracking. | DFS requires backtracking. |
You will never be trapped in infinite loops. | You may be trapped into infinite loops. |
BFS is slower than DFS. | DFS is faster than BFS. |
[wpusb]