Generic applications-graph depth (breadth) traversal is preferred. idiom solitaire example, including code downloading.

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.