10k

DFS vs Backtracking

DFS-depth first search

Traverse a graph from a now and to the leaf, and then go backwards and then traverse to the leaf.

Each time it goes to the deepest.

BFS-bread first search

Traverse a graph level(or layer) by level. Traverse all its neighbor first, and then their neighbors one by one.

Backtracking

Traverse a graph using a DFS manner while only traverse those path that's qualified(qualified means possibly has solution paths), so there actually would be a prune.

Backtracing vs DFS

Why we call it a bfs with prune? Normal bfs is just traversal. But backtracking is doing something when traversal. So, on each node, on that moment you reach the node, you will have to choose if the node is valid so you abandon it(prune) or you include it and from this node you start doing a small range of traversal.

Thoughts? Leave a comment