BFS graph theory summary

1. With regard to the BFS Key_word:

①hash compressed state or recorded state prune state ② ③ reverse BFS ④ bidirectional BFS ⑤ ⑥ special initialization VIS array of FIG searches dynamic priority queue ⑦ ⑧ digit search Refine_Results

Here is explain one by one:

1.hash compressed state or recording state:

  When too much state boundary and also difficult to store a wide array of topics or state space requirements more demanding, it is necessary to use the time required to save the state of compression to a state or a way hash state corresponds to a one-dimensional integer whether access to an array of records, when the data is too discrete consider using a map, but the corresponding time complexity will increase, if we really want to limit all states in a smaller range, you can use double hash, but most of the state relatively speaking, not too difficult, he said but for each search state study how to design transfer, a bit like DP, DP who search, regardless of home.

2. Status pruning:

  Pruning is no search without a soul, no matter DFS or BFS, DFS for us in terms of layer by layer to find, when we know that a child can not find the tree of the result, or the state has more when the condition is no longer accessible through expansion, but does not represent, I would be less than the current optimal solution optimal solution means that my child does not exist in the tree, instructions in this section, see ⑦. But the rigorous certification process requires pruning, pruning blind desirable, according to the specific design topics pruning conditions in the state transition, this is not what rules to follow in the BFS, each question in the title means that you need excavate pruned implied condition, for example: when reaching the same state, Dis1 <Dis2, less obvious, will be cut off subsequent DIS2, because at this point has the same subsequent transfer, but at this point the most excellent choice, and the choice of optimal results will be better than all other options, so pruning, it will find only a clear similarity relationship, and there is a clear need to have the merits of the state of pruning state, but in the title pruning can be difficult to find a relationship, which requires further proof of deduction and, when this is to learn, to learn will find the DP, through a variety of pruning the search is DP, recursion does not take every possible means of access status.

3. Reverse BFS:

  For example, there are N individuals in a maze, find the fastest man out of the labyrinth? So we consider the issue forward for N individuals so they quickly out of the maze, then request N times BFS, relatively few steps, then when N is large enough, blasting the stack, the stack does not require a large map will burst, then the anti to consider, we change the kind of question is asked, there is a maze of people, there are N exit, will he get out the fastest from which exports? If you ask, we will be thinking a lot of ideas, but the title will not be so easily transformed, we transform this question, there are N M individual outlets subject us how to solve, one solution is to build chart, Floyd shortest seek to compare the size complexity is O ((N + M) ^ 3 + (N + M) ^ 2), we are given here BFS way, as time complexity can only say revel, but the idea is this not a good idea, let's compare the size of N and M through small as a search starting point, then we Dis set the first search for the optimal solution, if no solution is greater than Dis also the second search, certain no solution, out of the way of the optimal solution by constantly updated constantly searches search complexity should be O (MIN ( N, M) * ans Between --O (MIN (N, M) * dis first), then the time at any point on the graph traversal is (N + M) ^ 2, multiplied by min (N, M), then the maximum time complexity is a (N + m) ^ 2 * Min (n, m), for a certain time complexity than the first, so that other methods may be used to optimize the queue dijkstra, O ((N + m) * Log (N complexity + M) * min (N, M)), for a better way to now, I do not know, of course, is not the shortest path within the scope of our discussion, because some cases can not be handled, and the subsequent access, so a little change can only use the BFS.

4. Bidirectional BFS

 

Whether or from the start began to expand from ans, geometric growth trends are to all intents and start the search party will explode stack, but the road between ans and start small, find the middle point through two-way search this way will definitely be more rapid, chart compares the image is not very ugly, but the general idea is manifested. Too many states apply to the transfer direction, but the shorter distance of the situation.

The array of specialized VIS

For a map of our vis = 1 to access, vis = 0 when not accessed, the second time you need to use memset, but time is too long, we put it another thought, for when vis = n, is visited , vis! = 1 is not accessed, so if vis is not N, then it is not initialized, then for 1 or 0 after the first pass after vis array, then we make n = 2, you can not initialize, the third time equal 3, and so on.

Figure 6. Dynamic Search

Figure circumstances will change with the timeline, you need to add a time dimension in the dimension of the state, but different states at different times, with different times to understand the state to a different state, then the search for a dynamic figure, not simply vis array, but to record overlay timeline states.

7. Priority Queue Search

For the priority queue optimized search, must prove extend the current ratio is not necessarily the optimal solution for optimal expansion of the optimal solution, that is not currently the best in the future is not necessarily the best. Otherwise, use the priority queue optimized search will fault.

8. Digital Search

Although this search write this, not what needs attention, but that very basic digital search, it seems unlikely, but some do. More of a K-nary, what I find with the division. For example, a 500 number, how modulo?

Think elementary school division algorithm how to write? Except it was not a bit? How many can do.

Guess you like

Origin www.cnblogs.com/lunatic-talent/p/11415792.html