Links
Similarities
- same time complexity
Differences
Parameters | BFS | DFS |
---|---|---|
Data structure | Queue | Stack |
Approach | All nodes on the same level is traversed before moving to the next level | Prioritizes going as far as possible and then backtracks when no further path is available |
Conceptual difference | Builds the tree level by level | Builds the tree subtree by subtree |
Nature of ADT | FIFO (queue) | LIFO (stack) |