Pre-balanced tree --BST

On one: balanced tree - Preface

The BST (Binary Search Tree) binary sort tree, which is defined as: binary sort tree or tree is empty, or a binary tree satisfying the following properties:

  ① If its left subtree is not empty, then the value of the left sub-tree, all the nodes are less than the value of the root node;

  ② if it is non-empty right subtree, the right subtree of the values ​​of all the nodes are greater than the value of the root node;
  ③ left and right of each sub-tree itself is a binary sort tree.
  Referred to above properties binary sort tree properties (BST properties), it is actually a binary sort tree satisfies BST binary nature. Simple explanation for the left subtree .val <root .val <right subtree .val.
  Obviously, in order traversal of BST is increasing sequence of val.
  BST beautiful level of support we insert nodes, delete nodes, query prefix successor (will explain later what is the prefix successor), the query node ranking queries small (or large) number of k. Because of the small number than the current node in the left subtree, larger than the current number of nodes in the right subtree, so keep on recursive binary tree, it is easy to find this number should be in the position.
  However, this section does not give us BST implementation code, very simple, BST is not commonly used (except possibly lazy nobody code BST_tree in the contest).
  We specifically explain. Analysis of the time complexity of the angle, the random data (remember words), the binary tree since generally have logn layer, it is desirable for the complexity of the operation O (logn), as shown:
   
  When the binary difference between the left and right subtrees almost the same height, we call the balance, but, once inserted into the monotone sequence, so it is easy to degenerate into a BST chain, then the complexity of the operation will be subsequently reduced to O (n) Figure:
  Since a single insertion requires O (n), then the worst overall complexity is O (n ^ 2), BST does not apply to a special data structure.
  So we generally realize BST, but by all means, so that while the nature of BST is not destroyed, so nearly balanced binary tree, which is a balanced tree derived.
  BST satisfy properties, and inorder traversal same binary sort tree is not unique, which gives us change the shape of the tree without changing the basic properties of BST.
  Next, we will introduce treap, utilizing random idea to maintain the balance of balanced tree.

Guess you like

Origin www.cnblogs.com/Yu-shi/p/10988539.html
BST