[More • algorithm • May 25th issue] universal algorithm (a): Search +?

Preface ▎

  See this title, you are not feeling puzzled, why is Search +, rather than search, Xiao Bian will not be wrong, in fact, this blog will let you see all kinds of games are played search.

▎ pre-skills

"Basics"

  Search: dfs and bfs (poke quickly get started here) .

"dfs and bfs similarities and differences."

  The same point: dfs and bfs are searching for, is to find the point.

  Different points: dfs depth-first, do not hit the brick wall does not look back, bang searched a road, it is more tricky, but the code less, beating write, most people like to use. The bfs is based on breadth as a priority, layer by layer traversal, more rational compared dfs it, but when the bad state of storage, you can only use the dfs.

▎dfs + bfs: the legendary bdfs

"iterative deepening search."

  In fact, no bdfs, people's real name is iterative deepening search.

  If you look at Baidu search, then the degree of your mother will tell you: In computer science, an iterative deepening search (iterative deepening search) or rather an iterative deepening depth-first search (iterative deepening depth-first search ( IDS or IDDFS)) is a state space (state diagram) search strategy. Depth-first search algorithm in this search strategy, have a depth limit will continue to run repeatedly, and at the same time relax the restrictions on the depth of the search until you find the target state. IDDFS and breadth-first algorithm is equivalent, but use a lot less memory; at each iteration, it will order depth-first algorithm, traversing the search tree node, but the first time the cumulative access node It is actually a breadth-first order. (Copy from Baidu)

  He said that for a long time know nothing, then take a look cited cases of it.

"references"

Example - Egypt scores

  This question first to think bfs, how to store the state, which is obviously not good store.

  Dfs use it? But he said he was powerless, because they do not know the score composed by several, do not know each denominator upper limit is how much, dfs might have found it, a road go black.

  How to do it? Both searches encountered a bottleneck, then we might look at combined two search mode.

"core algorithm"

  We dfs as the main body, but the disadvantage is that dfs farther and farther, then we can bfs injection characteristics of: Drilling down, we might as well set a variable to store the number of layers, good dfs limit to reach this level does not allow continue the search.

  This is not only a simple idea, also it combines two ways of searching.

"algorithm template"

  

  (Copy from cdcq of ppt)

▎ Search + pruning

  If the inter-state searches for the connected edge based on the transfer order, it will form a search tree and pruning it is useless branches will be cut in order to increase efficiency.

  Pruning optimization (stamp and running quickly here) .

▎ Search + compressed state

"Status Compression"

  Sometimes you may not be able to save a map with a two-dimensional array, because the data is too large scale.

  It may be time to think about the complexity of the optimization algorithm.

  We can use the compressed state, the chart is converted into a binary, one-dimensional array can be able to save the entire map, or use lowbit also a good way algorithm.

"references"

  Or N Queen title and solution to a problem (poke here to learn) .

"Status compression applications."

  State compression optimization dynamic programming examples succinctly (poke here to learn) .

▎ Search Search +

  Yes, this is bi-directional search.

   Bidirectional BFS, is in the start and end are well aware of the situation, the start and finish at the same time into the team, or into two teams, joint bfs, when the two first met as the optimal solution.

  The purpose is to solve the problem of too many search access state, the time complexity of optimizing a lot of one-way search ratio.

Guess you like

Origin www.cnblogs.com/TFLS-gzr/p/11248509.html