Based On | Breadth First Search (BFS) | Depth First Search (DFS) |
---|---|---|
Description Of The Algorithm | Breadth first search (aka. BFS) is a searching method used to search (or. explore) for a node (or the entire structure) by traversing from root node and explore the search in level by level. | Depth first search (aka. DFS) is a searching method used to search (or explore) for a node (or the entire structure) by traversing from root node and explore the search as deep as possible until a dead end is found. |
Data Structure Used | Breadth first search uses a Queue. | Depth first search uses a Stack. |
Similar To | Breadth first search is similar to level-order traversal. | Depth first search is similar to pre-order traversal. |
Speed | BFS is slower than DFS. | DFS is more faster than BFS. |
Advantage | Breadth first search always finds a shortest path from the start vertex to any other for unweighted graphs. | Depth first search may not finds a shortest path. |
Algorithm Type | A greedy algorithm. (update neighbors of closest nodes first). | A backtracking algorithm (explore one path until dead end). |
Time & Space Complexity | BFS takes O(bd) time and O(bd) space | DFS takes O(bh) time and O(h) space |
Applications |
|
|
Traversal Example |
8, 3, 10, 1, 6, 14, 4, 7, 3
|
3, 1, 6, 4, 7, 10, 14, 13
|
Simple GUI Notepad Using Ruby
GUI Notepad Using Ruby Code require 'tk' class Notepad def saveFile file = File.open("note", "w") ...
-
Bresenham' s line drawing algorithm for drawing a line in a computer screen by using integer arithmetic operations only. It is more eff...
-
Prime Factors Using Bash Script To do solve this problem we use the factor command available in the shell. The factor command prints the p...
-
C Program For Rotation Of An Object We have already described what is Rotation in previous posts. Here is the c code using graphics.h li...