Tree basic definition tree Definition
Number is a finite set with n nodes. Is a tree structure.
Node category
Node degree: the degree of node that A node has. For example, if A node has two subnodes, B and C, the degree of node A is 2. <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + Asn + cjxwpsjnzbyjuw.vcd4kpc9ibg9ja3f1b3rlpgo8cd48aw1nihnyyz0 = "http://www.2cto.com/uploadfile/Collfiles/20140504/20140504090027123.jpg" alt = "\">
Relationship Between Nodes
Child node: A child node is a child node. For example, Node B and node C are child nodes of node.
Parent node: opposite to child node. For example, node A is A parent node of Node B and node C.
Sibling nodes: Child Nodes of the same parent node are called sibling nodes. For example, B and C are sibling nodes.
Tree Storage Structure
Analyze the following different representations based on the first figure at the top of the blog. Parental notation
The meaning of the two parents is described above. Data indicates each node, and parent indicates the table address of the corresponding parent node.
This structure is convenient for searching for parent nodes, but it is troublesome for searching for child nodes. You need to traverse the entire tree.
Child notation
The child representation is opposite to the parent representation. The parent node records its child node and obtains the maximum degree of data. In this figure, the maximum number is 3.
Parent-Child notation
Based on the evolution of the Child notation, the two-parent notation is combined with the child notation.
In this way, you can easily obtainParent and Child Nodes.
However, to retrieve a certain number of sibling nodes, we still need to traverse the entire tree.
Child brother notation
The parent node records the first child node and the first child node records the child node and brother node.
Based on business requirements, you can select different representations. Each representation has its own advantages and disadvantages.