First round of Data Structure: Tree

Source: Internet
Author: User

Tree is an important part in both the introduction of data structure and the soft test. The introduction to data structure is more detailed than the soft test, below I will integrate this part with examples:

In general, the structure is as follows:

The overview part is an explanation of some basic concepts and properties. Both forests and Binary Trees have special forms of trees. The Decision Tree and the Haffman tree are essentially trees and can also be used as trees, use the basic knowledge of trees (including binary trees) to describe and solve some practical problems. Next we will look at it in sequence:

I. Binary Tree

1. [Overview]

Binary Trees are full, completely, and not completely. The so-called Full Binary Tree is a sub-node with no difference, all the locations should have,

If the binary tree lacks the subnode 4, it is a complete binary tree. If the subnode 2 and 4 exist, if the position 7 or 5 is left blank, it will be completely changed from one to an incomplete one.

The difference between a full binary tree and a non-full binary tree is that there is a missing layer, and whether the existence of subnodes is continuous.

[Example Analysis] (from "Introduction to Data Structure" 125)

If 20 nodes exist in layer 7th of the Complete Binary Tree, the number of leaf nodes of the entire full binary tree is ______.

[Resolution]:Because it is a Complete Binary Tree, the last layer of the tree must be missing, that is, the number of nodes is smaller than the (n-1) power of 2. Layer 1 is full, with a total of 32 nodes. According to the question

The tree has a total of seven layers, and according to the nature of the full Binary Tree, these 20 nodes are the sub-knot points in the 10 nodes of the 6th layer. On the sixth layer, the remaining 22 nodes are leaf nodes.

Therefore, there are 20 + 22 = 42 leaf nodes in the tree.

2. Conversion between trees and Binary Trees

Let's talk about it in graphs. Here we can understand it.

1) First connect all the brothers on the tree to obtain the picture on the right of the source image:

2) Keep the first sibling node in each layer as the left subtree node of the layer and disconnect the connection between C, D and the root node, take B, C, and D as a line and rotate the 45 degrees angle clockwise with B as the center. Then, the following figure is displayed:

Actually, yes.In this case: After all the sibling nodes are connected, the first one on the left of all sibling nodes in each layer serves as the parent node of all sibling nodes. Other sibling nodes maintain the formation, take this node as the center for rotation, so that the final binary tree is obtained.

Ii. Forests

The forest can be seen as the virtualization of a real tree, which is also composed of multiple trees. Here, the knowledge points are mainly the conversion between binary trees.

The conversion between forests and Binary Trees is actually an extension of the conversion between trees and Binary Trees. After each tree is converted into a corresponding binary tree, all the root nodes are connected as brothers, and the transformation from a binary tree to a forest is an inverse process.

This data structure is messy for the first time. It's hard to hear it. It's not just a figure or a letter, and the whole world is filled with these two things. But after all, "The eyes are the bears and the hands are the heroes", so I learned a bit about the data structure learning skills:

1. instantiation

"This instantiation is not an actual instantiation." It is mainly integrated into life, replaced by common familiar things in life, or helps to understand these abstract and empty theoretical structures.

2. Hand-brain combination

In this course, many knowledge points require additional thought diagrams to help you understand, such as tree, graph, or pointer pointing. This requires us to use our hands and minds to help us understand and solve the problem with images on paper.

3. Shen Xin

In the face of those complex professional terms, do not fear the rich tree map, lest you sink your mind. In order not to let your mind sink, you must sink your mind. If you can understand these two words, you will "sink your mind": Calm down and think about it carefully, in fact, the problem is not a problem.

This data structure is a paper cat, because it does not even count as a tiger. Come on!

First round of Data Structure: Tree

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.