Introduction to the Dictionary tree
Dictionary tree, also known as the word lookup tree, is a key tree, a typical application is used to statistics, sorting and saving a large number of strings (but not limited to strings), so often by the search engine system for text frequency statistics.
The dictionary tree has 3 basic properties:
1, the root node does not contain characters, the rest of each node contains a character;
2, from the root node to a node, the path through the characters connected to the node corresponding to the string;
3. All child nodes of each node contain different characters.
The structure of the dictionary tree is generally shown in the following illustration:
As an example of a string, we can write its storage structure in the following form:
#define MAX //Character Set size/
*
dictionary tree storage Structure
* *
typedef struct node
{
struct node *next[max]; There may be a max character int count under each node
; }trienode,*trietree the number of strings that are public prefixes from the root node to the current node
;
Here, because we use a character set of 26 lowercase letters, Max is 26. You can compare this data storage structure with the storage legend above to deepen your understanding. It is easy to see that the dictionary tree is a typical space for time, storage space is very large, this is very useful in the mass of strings.
The dictionary tree has the following 2 advantages:
1. Use the common prefix of strings to conserve storage space.
2. To minimize unnecessary string comparisons, query efficiency is high.
The application of Dictionary tree
The dictionary tree application is very extensive, below is excerpt from Baidu Encyclopedia 3 Application Introduction:
1, in the series of rapid error detection of the application
The dictionary tree application is very extensive, below is excerpt from Baidu Encyclopedia 3 Application Introduction:
1. The application of dictionary tree in Fast retrieval of string.
Given the n words of a cooked word, and a full text written in lowercase English, please write in the order of the earliest occurrence of all not in the list of familiar words. In this problem, we can use the dictionary tree, first of the ripe words to build a tree, and then read into the article to compare, this method efficiency is relatively high.