Current location - Quotes Website - Signature design - Discuss the tree structure (traditional tree, dictionary tree, hash tree, Merkle Patricia tree) in detail.
Discuss the tree structure (traditional tree, dictionary tree, hash tree, Merkle Patricia tree) in detail.
References in this paper: tree structure references

[Image upload failed ... (Picture-83B557-1539180310707)]

[Image upload failed ... (Picture-D6BF01-1539180310707)]

Property 1. Nodes are red or black, roots are black, and all leaves are black.

Real estate 2. Each red node must have two black child nodes. (There cannot be two consecutive red nodes on all paths from each leaf to the root, that is, red and black alternate with each other), and all simple paths from any node to each leaf contain the same number of black nodes (black height for short).

[Image upload failed ... (Picture-52c714-1539180310707)]

B+ tree is a variant of B tree and a multi-path search tree.

[image upload failed ... (image-C2CE8E-1539180310707)]

Properties of B+ trees:

1. All keywords appear in the linked list of leaf nodes (dense index), and the keywords in the linked list are only ordered;

2. It is impossible to hit a non-leaf node;

3. Non-leaf nodes are equivalent to the index of leaf nodes (sparse index), and leaf nodes are equivalent to the data layer for storing (keyword) data;

4. More suitable for file indexing system.

Therefore, the probability of allocating new nodes in B* tree is lower than that in B+ tree, and the space utilization rate is higher.

Tire tree is called dictionary tree, also called word lookup tree and Trie tree. It is a tree structure and a variant of hash tree. The typical application is to count, sort and save a large number of character strings (but not limited to character strings), so it is often used by search engine systems for text word frequency statistics. Its advantages are: using the common prefix of strings to reduce the query time, minimizing unnecessary string comparison, and the query efficiency is higher than that of hash tree.

Three basic attributes of the tire tree:

Application of tire tree;

Give a vocabulary of n words and an article written in lowercase English. Please write down all the new words that are not in the vocabulary in the order of their earliest appearance. In this problem, we can use array enumeration, hash and dictionary tree to build a mature word tree first, and then read the article for comparison. This method is relatively efficient.

Given n different English names consisting of only one word, let you output them from small to large in dictionary order. Sort by dictionary tree and create dictionary tree by array. All the children of each node of this tree are obviously sorted by letter size. Traverse the tree first.

Establish a dictionary tree for all strings, and the length of the longest common prefix of two strings is the number of common ancestors of their nodes, so the problem is transformed into the problem of finding common ancestors.

[image upload failed ... (image-f00bd3-1539180310707)]

[Image upload failed ... (Picture-D70C23-1539180310707)]

[Image upload failed ... (Picture-8A3963-1539180310707)]

[image upload failed ... (image-69461e-1539180310707)]

[Image upload failed ... (Picture-987993-1539180310707)]

[Image upload failed ... (Picture-58F33C-1539180310707)]

References:

1、 blogs.com/pinard/p/6050306.html

4、QQ _ 33935254/article/details/55505472