Use cases of DFS and BFS
OriginalAbout 2121 words
Prerequisite Knowledge
Before reading this article, you need to first learn:
In real algorithm problems, the DFS algorithm is commonly used to enumerate all paths, while the BFS algorithm is often used to find the shortest path. Why is this the case?
Because recursive and level order traversals of binary trees are the simplest forms of DFS and BFS algorithms, this article will use a simple binary tree example to illustrate the reasoning.