Left Leaning Tree Learning

Source: Internet
Author: User

left-leaning tree (leftist trees)
Tree This data structure is really a lot of, two fork heap, in fact, is a binary tree, this talk about the left side of the tree (also known as "left Heap"), is also a tree.
Two fork Heap is a very good data structure, because it is very easy to understand, and only use an array, does not cause the waste of extra space, but it has a disadvantage, it is difficult to merge two binary heap, for "merge", "split" This operation, I think the most aspect is still rely on pointers, Change the value of the pointer can be achieved, if it involves the movement of elements, it is more complicated.
The left side of the tree with the two fork heap, is a true meaning of the tree, with the left and right hands, so the space overhead slightly larger, but it brings convenience to facilitate the merger. BTW: After writing a lot of programs, I found that "space change Time" is always a programming method that should be considered. :)
left to the left side, give people feel is the proportion of Zuozi is relatively large, in fact, it is similar, you can understand: the left component weight, that has been to the right, it will be able to find the fastest node can be inserted elements. So the next definition: the left-leaning tree is to its arbitrary subtree, the distance to the right to the insertion point (hereinafter referred to as "distance") is always less than the left to the insertion point distance, of course, and the two fork heap, the parent node is less than the value of the child node.


If the node itself is dissatisfied, can be inserted, that distance is 0, and then the distance of the empty node is recorded as-1, so we can conclude: the parent node distance = Right child node distance + 1, because the right child node distance is always less than or equal to the left child node distance. I marked the value of the distance in blue font.
The left side of the tree and must be balanced, even if it can be very unbalanced, because it does not need to balance, it only needs like a binary heap as a function, plus the merger is convenient, now look at the left-leaning tree merging algorithm,

This algorithm is actually very suitable for the recursive return to do. For the left-leaning tree, this merging operation is the most important and basic.
Conclusion: The advantage of the left side tree than the same binary pile is convenient to merge, the disadvantage is that the programming complexity is slightly higher (also high not go to where), occupy a little space (actually also big not go where).

Left Leaning Tree Learning

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.