The AVL Tree of STL

Source: Internet
Author: User
The associative container is said to be an associative container, each data has a key value and a real value, when the element inserts the associative container, the container according to the key value size, according to the specific rule (Set,multiset,map,multimap is the red black tree, Hash is a hash table) to place the elements in a specific location, so the associative container will not have push_back () Pop_back () Push_front () Pop_front () and other operations;
First, take a look at the depth of the tree and the height of the node, and define the number of bars that the root node passes through to the other node. Called the path length, the maximum path length from the root node to the tree's leaf node is the depth of the tree; The maximum path length of the node from one node to the next is called the height of the nodal point;
AVL Tree Introduction because the binary search tree under certain conditions is still causing performance degradation, the AVL tree is a two-fork search tree with an additional equilibrium condition, which is balanced to maintain the depth of the tree in O (Logn), but the general equilibrium condition is that the left and right subtrees of each node are the same height, This is too strict, therefore, the AVL tree to the second, only require that the left and right of any node is not more than 1 of the height of the tree; Insert operation, the AVL tree is focused on its insert operation, if an insert operation does not cause the original tree structure imbalance, you do not need to adjust the tree structure ; However, if an insert operation causes an imbalance in the original tree structure, the AVL tree adjusts to the node x at the deepest of the balance-corrupted node. This is divided into several cases: 1: The insertion position is on the left subtree of the left child node of X, 2): The insertion position is on the right subtree of the left child node of X; 3): The insertion position is on the left subtree of the right child node of X, 4): The insertion position is on the right subtree of the right child node of x;
The total comes, 1) and 4 can be grouped into one type of case (left left, right right) This situation is called: lateral insertion, can be done through a single rotation, the specific process is: ①: By the X's left child node X_left lifted the X node automatically sinks, and then readjust node ②: Make X in X_left The right sub-node position ③: The X_left's original right subtree is called the left subtree of x;
2) and 3 can be grouped into one type of situation (left, right), this condition is called the inside insert, must pass two times single rotation to fix, also be double rotate, the concrete process is: ①: For unbalanced node x Zuozi (if it is the case of 3) first a single rotation; ②: Then a single rotation of x;

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.