Known Point Set v = {V1, V2, V3.. vn} is connected by edge
Deep priority model:
Void find1 (V)
{
While (breadth ++)
{
Find1 (new vertex); // Recursion
}
}
We can see that he first searched the first branch of a branch until the end, and then searched the first branch of 2nd ....
Breadth-first model:
Declare the global point set R = {R0} as the starting node.
Void find2 (r)
{
While (breadth ++)
{
R. Add (new vertex );
}
R. Remove (old Point );
While (new breadth ++)
{
Find2 (r); // Recursion
}
}
The following side chart is used as an example:
1
//
2 3
// Logs/
4 5 6 7
The execution sequence of depth priority is:
1245367
Breadth First:
1234567
Depth first is generally suitable for finding the longest path. In this example, the depth is preferred.
Breadth First is generally suitable for finding the shortest path or exiting after finding it.
The idea of idiom solitaire is:
0. analyze all idioms, convert the Chinese characters at the beginning and end into numbers using Unicode, And then subtract short. maxvalue to make them distributed within the short range to save memory. If the string is used, the memory is relatively waste.
1. Using the generic container dictionary to search for keys is the Hash hash feature of O (1), two dictionaries are created. One is all idioms and the other is multiple idioms of the header index.
2. Enter an idiom and click the button next to it. The tail node is used as the header and the search is performed in depth first. (exclude the ring and check the complexity of the ring. O (1 ))
3. check whether a longer dragon appears every minute.
CodeDownload
Http://www.dullwolf.cn/Idiom.rar