8.5 binary sorting tree and balanced binary tree

Source: Internet
Author: User

8.5 binary sorting tree

An ordered linear table is convenient to search for. However, insertion and deletion operations consume a lot of time, because after insertion and deletion, a large amount of data is moved to maintain a linear order. The binary sorting tree can be used to solve this problem.

Binary sorting tree, also known as binary search tree. It is either an empty tree or a binary tree of the following nature:

1) if its left subtree exists, the value of all nodes on the left subtree is smaller than its root node value;

2) if its right subtree exists, the value of all nodes on the right subtree is greater than the value of its root node;

3) its left and right subtree are also Binary Decision Trees.

The purpose of constructing a binary sorting tree is not to sort, but to speed up searching, inserting, or deleting keywords.

The binary sorting tree is stored as a link, which keeps the link storage structure from moving elements when performing the insert or delete operation. After finding the proper insert and delete locations, you only need to modify the link pointer.

8.6 balanced binary tree

When constructing a binary tree, it is constructed in sequence by elements in the array to satisfy the nature of the binary tree. When constructing a binary tree for an array in a forward order, it will become a right-oblique binary tree without a left subtree, which will affect the search efficiency. Therefore, a balanced binary tree is constructed.

Balanced Binary Tree: a binary sorting tree. The difference between the left and right decision trees of each node is at most 1.

Construction principle: When a node is inserted, first check whether the balance of the tree is damaged because of the insertion. If yes, find the minimum imbalance tree, adjust the links between nodes in the sub-tree with the minimum imbalance and rotate them accordingly to form a new balance tree.

 

This article is from "Li Haichuan" blog, please be sure to keep this source http://lihaichuan.blog.51cto.com/498079/1282363

Related Article

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.