I am a "tree"

I am a "tree"

Click "Hollis" above to follow me, and the exciting content will be presented immediately.

Full text: 1800
Reading time: 3 minutes
I am a tree. A kid in our data structure family-"Stack" has already introduced you to our family (I am a "Stack"). The reason why I call Zhan as a child is because my father and I-the array are the same generation.

The main reason for the existence of a family like ours is that although their families are very strong, they have certain limitations. Everyone knows that whether it is an array, a linked list, or their little dolls (stacks, queues), etc., there is only a simple pre-order relationship between the stored data.

Now that we're talking about this, let's show you the whole family of data structures. After all, the "stack" you know is only a junior, and doesn't know much about the history of our family.

Data structure family


Data structure has two main functions. The first is to store data, and the second is to reflect the logical relationship between the stored data. Note that the logical relationship is not the physical location of their storage in the computer. Therefore, according to the logical structure of the data you store, it can be divided into these major branches:

  • Collection
    What is the relationship between the data stored in someone else's home they are not the only possible relationship is the same in the same collection.
    I am a "tree"

  • In
    their home with a linear structure , the data stored for others is ordered, and the data is logically stored end to end. Therefore, there is a one-to-one relationship between elements. For example, the array family you know has a linear structure.
    I am a "tree"

  • Tree
    Hey, this is our family branch of the matter, there is an element of our storage-many relationship.

Graph structure
pattern is a branch structure of complex data structures. The relationship between data elements is arbitrary. Any two data elements can be related.
I am a "tree"

The arrays, queues, stacks, and linked lists that everyone knows all belong to the branch of linear structure. Today's protagonist, that is, me and my "tree" family are in the big branch of the tree structure.

As you may have guessed, I am the patriarch of the tree structure of the entire data structure family. As a large family branch, we certainly have the basic function of the entire data structure family-data storage. In addition, the entire tree branch is mainly used to store data collections with a tree structure. To put it plainly, the data we store for others is hierarchical. It's like an upside-down tree in nature.

Let me first talk about some restrictions and requirements for us to save data. Each element we save for others is called a node, and we generally have a specific node called the root node, and the rest are called non-root nodes. Let me show you a standard tree, and then use this picture to introduce the concepts of leaf nodes and parent nodes.
I am a "tree"

H节点是O和L的父节点,O和L是H节点的子节点。
H节点是根节点,因为他没有父节点。 
I、S和L节点是叶结点,因为他们没有子节点。 
I和S是兄弟节点,因为他们的父节点都是O节点。

Okay, that’s all, it’s time to show you my family members. As a large family of tree families of data structures, I have many descendants. Let me show you my family tree first:
I am a "tree"

I have two sons: the elder son has an ordered tree and the younger son has a disordered tree. The eldest son is the pillar of the family and has taken on a lot of family work. And my youngest son is a relatively free child who cares nothing about everything, so people sometimes call him a free tree.

Let me talk about this little son I love very much-Disorder Tree.

Unordered tree


Unordered tree, it is also a tree structure. Except for the relationship between parent and child nodes in the tree, all child nodes of the same parent node have no relationship. In the tree, this relationship is the order, such as who is Who is behind? Therefore, it is called a disordered tree. In addition, because my little son is too free, he has not yet given birth to a baby for me. Therefore, my youngest son is a lonely man.

Let's talk about his data storage in detail. As mentioned earlier, the data he stores are only related to the parent and child nodes. If you ask him to help you store the three data of A, B, and C, there are three cases of one parent node and two child nodes.
I am a "tree"

Regardless of the positional relationship between the two child nodes, they are all the same tree. That is, ABC and ACB are considered to be the same tree.

Ordered tree


Let me introduce my eldest son, the heir to the entire tree family. He really did all the things an eldest son should do. He and his children took almost all the work of the tree family.

The difference between it and the unordered tree is obvious, that is, in the ordered number, there is an order relationship between the child nodes. If you ask my eldest son to help you store the three data of A, B, and C, there are 6 cases of 1 parent node and 2 child nodes.
I am a "tree"

As long as the order of the two nodes is changed, it is a new tree. ABC and ACB are considered two different trees.

From the family map above, we can find that my eldest son also has many children. Among them, my three famous grandsons are Binary Tree, Hoffman Tree, and B Tree.

Today's young people are very personal, and they have a lot of requirements when storing data for others, but fortunately, young people should have a little personality. Thanks to their respective characteristics, the tree family can be so powerful.

Regarding the introduction of the younger generations of ordered trees, let them do it by themselves later. I am tired after talking so much about the old bones.

-MORE | More exciting articles-

  • I am a "stack"
  • Java engineer's road to becoming a god (2018 revision)
  • Go language, Docker and new technology
  • Multiple implementations of distributed locks

    If you see this, you like this article.

    Then please press and hold the QR code to follow Hollis

    I am a "tree"

Guess you like

Origin blog.51cto.com/13626762/2545023