- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Difference between BFS and DFS
BFS and DFS are graph traversal algorithms.
Breadth First Search (BFS) algorithm traverses a graph in a breadthward motion and uses a queue to remember to get the next vertex to start a search when a dead end occurs in any iteration.
Depth First Search (DFS) algorithm traverses a graph in a depthward motion and uses a stack to remember to get the next vertex to start a search when a dead end occurs in any iteration.
Following are the important differences between BFS and DFS.
|1||Definition||BFS, stands for Breadth First Search.||DFS, stands for Depth First Search.|
|2||Data structure||BFS uses Queue to find the shortest path.||DFS uses Stack to find the shortest path.|
|3||Source||BFS is better when target is closer to Source.||DFS is better when target is far from source.|
|4||Suitablity for decision tree||As BFS considers all neighbour so it is not suitable for decision tree used in puzzle games.||DFS is more suitable for decision tree. As with one decision, we need to traverse further to augment the decision. If we reach the conclusion, we won.|
|5||Speed||BFS is slower than DFS.||DFS is faster than BFS.|
|6||Time Complexity||Time Complexity of BFS = O(V+E) where V is vertices and E is edges.||Time Complexity of DFS is also O(V+E) where V is vertices and E is edges.|
- Applications of DFS and BFS in Data Structures
- BFS vs DFS for Binary Tree in C++?
- Difference between C# and .Net
- Difference between Process and Thread
- Difference between Concurrency and Parallelism
- Difference between localhost and 127.0.0.1?
- Difference between JCoClient and JCoDestination
- Difference between String and StringBuffer.
- Difference between StringBuffer and StringBuilder.
- Difference between CPU and GPU
- Difference between TDM and FDM
- Difference between CRT and LCD
- Difference between GUI and CUI
- Difference between LAN and WAN
- Difference between LAN and MAN