Why do we need to balance the binary tree?

Source: Internet
Author: User

Foreword : Recently read "The Foundation of Computer Science" as well as eldest brother's code, very need the related basic knowledge content of the tree structure, in see the source of the eldest brother about BT and RBT, will balance tree and two fork sort tree, relate together. A brief description is recorded. first, how to adjust the imbalance tree to the balance tree

Well, how to adjust the content, many people have summed up, I jiehuaxianfo, directly quoted (well, I will not admit that I will not, and very lazy)

Animation demo Balanced binary tree rotation Two, why to adjust

When I first thought about the problem, is looking at the eldest brother code, I first look at is the BT code, and then I see the RBT, see the rotation balance processing, and then I was very Meng, do not understand why to turn, because not to turn, is also in line with the standard tree. There is a very stupid problem is: I always thought BT is two forks, in fact, his grandmother a leg, is multi-channel search, I pooh, exposure IQ.

Anyway, why adjust: balanced binary tree

In short, the balanced binary tree, must be a two-fork sorting tree, the reason that the sorting tree, adjusted to the equilibrium state, is to enhance its lookup performance and reduce the time complexity when the binary sort tree is approximately chain.
third, the motive of writing a blog

In fact, from the above content, I have almost no content to express the technical problems, then why do I write this blog.

1, I have linked the content that I have learned. Because the boss recommended it to me. The basics of computer science recently saw the tree structure and the table structure model, and I've been thinking about the contents of the binary sort tree, including how the tree is stored. Today, when watching BT and RBT, suddenly feel that the performance of RBT will be higher than BT, why, because the characteristics of the binary sort tree will be simpler than the multi-channel search to deal with, you think about it: two fork sorting tree, not in this side, is over there (two choose), and multi-channel search, I do not know is a few selected Ah, And split, well, that's not my excuse for low IQ.

2, why do you need to sort. I remember one of my teachers said: Sorting is for better storage and faster operation.  And then, based on this, combined with the table structure model I read, I thought of a problem (or found a problem): How to set the primary key, before I have done the system, the primary key are adopted by the self-added, but now the system, are randomly generated unique identification code. I was thinking, if the order is to improve the efficiency of the operation, then why discard the primary key from the way of the increase.  If there is no primary key, then the embodiment in the index will be what.  I've checked all these questions. But the main point is to say: knowledge can be linked, when the knowledge of the connection, a sense of achievement. Iv. Personal Summary

Today, on the whole, is a perfect day. Because I saw the code before the boss, some places are not very clear, and then have to ask a thick cheek. Although the face is not red, but in the mind has always despised their IQ. But, I persisted, today all the code read, I said that my understanding, seemingly still not all right, but I found the feeling.

In fact, I still think, exactly what scene, with the tree structure of the child brother notation. Because now most of them are parents ' notation.  Today, I look at the relevant content of BT, a modern engine, I rely on, multi-channel search, sure to save the Brothers node ah. Well, it's just a blind thought.

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.