Dictionary Tree Overview

Source: Internet
Author: User
Tags character set lowercase

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.

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.