Data Structure-tree (Definition and storage structure)

Source: Internet
Author: User

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.




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.