Logical structure and storage structure of the tree

Logical structure of the tree

Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

Tree storage structure

1. The first method of expression

Insert picture description here

Insert picture description here
Insert picture description here
In order to find sibling nodes, firstChild and right are added
Insert picture description here

The second way to express

The number of pointer fields is determined by the degree of the tree
Insert picture description here

Insert picture description here
The solution to the extra pointer domain wasting space is to
allocate several pointer domains if there are a few children, so as to avoid the pointer domain occupying space
Insert picture description here

In this way, the number of pointer fields of each node may be different due to the number of children, so it is impossible to use one node structure to represent all nodes, causing programming difficulties

Insert picture description here

The third method of expression

Insert picture description here
Insert picture description here
Insert picture description here

Child brother notation

Insert picture description here
Insert picture description here
Insert picture description here
How to find sibling nodes? How to find the child nodes through the sibling pointer
? Find the left child node through the child pointer, and then find all the right sibling nodes of the left child

Guess you like

Origin blog.csdn.net/m0_53157173/article/details/114681150