Wide search and deep search

Depth-first search:

dfs, using recursive functions, search through the stack structure.

template:

· Dfs (state)  
-if state is the goal state then
·dosomething
–else
· For each new state
-if the new legal status
»Dfs (new state)
· The main program:
· Dfs (initial state)

BFS:

bfs, using recursive functions, search the way through the queue.

 

dfs is a search for a tree, through a certain sequence to each of the sub-branches of the tree traversal all over again. . It is similar from the starting point, first of all point in one direction will change direction traversed ...... "do not hit the brick wall does not look back."

bfs is traversing a certain depth, kept up by way of a queue, push side edge pop, known traversed until the queue is empty. bfs relative dfs for more use of space. DFS is a space-efficient, DFS no need to save the state of the search process, in BFS search process and the need to save the state searched, and generally require a queue record.

 

Guess you like

Origin www.cnblogs.com/lbssxz/p/10993159.html
Recommended