Trie

==In computer science==, a trie, also known as a prefix tree or a dictionary tree, is an ordered tree used to hold associative arrays, the keys of which are usually strings. Unlike a binary search tree, the key is not directly stored in the node, but is determined by the node's position in the tree. All descendants of a node have the same prefix, which is the string corresponding to this node, and the root node corresponds to the empty string. In general, not all nodes have corresponding values, only the keys corresponding to leaf nodes and some internal nodes have relevant values.

The term Trie comes from retrieval. According to etymology, the inventor of the trie, Edward Fredkin, pronounced it /ˈtriː/ "tree". [1][2] However, other authors pronounce it as /ˈtraɪ/ "try". [1][2][3]

In the illustration, the keys are labeled in the nodes, and the values ​​are labeled below the nodes. Each complete English word corresponds to a specific integer. A Trie can be thought of as a deterministic finite state automaton, although the notation on the edges is generally implied in the order of the branches.

Keys do not need to be explicitly stored in the node. The complete word is marked in the illustration, just to demonstrate the principle of trie.

The keys in the trie are usually strings, but can be other structures. The trie's algorithm can easily be modified to handle ordered sequences of other structures, such as a string of numbers or an arrangement of shapes. For example, a key in a bitwise trie is a string of bits that can be used to represent integers or memory addresses.

Table of Contents
1 Application
2 Implementation
2.1 Triple-Array Trie
2.2 Binary-Array Trie
3 Example
4 References The
application
trie tree is often used for search hints. For example, when a web address is entered, possible choices can be automatically searched. When there are no exact matching search results, the most similar prefix possible can be returned.

Implementation
== A trie tree is actually a DFA, usually represented by a transition matrix. The row represents the state, the column represents the input character, and the (row,column) position represents the transition state==. The query efficiency of this method is very high, but due to the serious sparse phenomenon, the space utilization efficiency is very low. A compressed storage method, that is, a linked list, can also be used to represent the state transition, but due to the linear query, it will cause low efficiency.

Therefore, the following two structures have been proposed. [4]

Triple-Array Trie
The Triple-Array Trie (Tripple-Array Trie) structure includes three arrays: base, next and check.

Two-array Trie
Two-array Trie (Double-Array Trie) contains two arrays of base and check. Each element of the base array represents a Trie node, that is, a state; the check array represents the predecessor state of a state.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325037242&siteId=291194637