The even-numbered group Trie tree, in fact, uses two one-dimensional arrays to represent the data structure of the trie tree.
An array is called base and the other array is a check. The transfer conditions are as follows:
For status S, receive character C, transfer to state T
Base[s]+c=t
Check[t]=base[s]
- Base array to store nodes
- Check array identifies the precursor information of the node
For root nodes, define:
The root node has a status of 0,\ (t_ root =0\) .
The base address of the root node is 1, which is stored in the base array subscript 0, so \ (base[t_ root]=base[0]=1\).
\ (check[t_ root]=check[0]=0\)
For a node NodeA in the Trie tree, the following information is available:
- Character ' A ', this is for people to see
- The state of the character ' a ', denoted by \ (t_a\) ,\ (t_a\) is an integer. From the root node, the conditional ' A ' is transferred to NodeA, which is:\ (Base[0]+code (a) =t_a=1+65=66\), where code (a) is typically the ASCII code for that character.
- The base address of the character ' a ', using the base array to save
- Because the NodeA of the node corresponding to the character ' A ' is the root node, i.e. \ (check[t_a]=base[0]=1\)
For the leaf node node_leaf, the base address defining the leaf node is begin, the state is T_leaf, code (NODE_LEAF) = 0,
Now to prove: check[t_leaf]=t_leaf
- Begin+code (node_leaf) =t_leaf get: Begin=t_leaf
- Base[begin+code (node_leaf)]=t_leaf get: Base[begin]=t_leaf
- Check[t_leaf]=base[begin] Got: check[t_leaf]=t_leaf
The 2nd and 3 points are obtained by the transfer condition, and the proof is complete.
In addition, in this article of Hancks, the following references are available:
3. Then set the check for this group of sibling nodes to Check[begin + a1...an] = begin; Obviously, the value of the leaf node I check[i] must be equal to I, because it is the first in the sibling node, and its code is 0.
It's a good idea.
In addition, for the leaf node, base[t_leaf]=-index, reference, wherein-index said: The leaf node represents the key words in the dictionary order. (When constructing an even-numbered group tree, the dictionary is loaded into TreeMap and is ordered)
Proof of leaf node check[t]=t in trie tree of even-numbered groups