Looking back data structure - red-black tree (a)

AVL trees and red-black tree is the same as the binary search tree, also known as red-black tree is to keep the "black balance" binary tree, red-black tree maximum height: 2logn, a red-black tree so several unique features:
  1, each node or black or red
  2, black root
  3, each leaf node (the last blank nodes) are black
  4. If a node is red, his children are all black node
  5, from any node to a leaf node, black node after as many as
  6, all red nodes are tilted to the left

enter image description here

  Before we define binary search tree node structure in the realization of the elements e for storing for storing left subtree left, right right subtree for storing objects and the like, and in the AVL tree than binary search trees AVL vary due to the need to maintain the height of the tree nodes around the child so much the height of an element of height for storage node;
  red-black tree is a binary search tree based on previous variant comes in red-black tree nodes only binary search trees and more than one element, node binary search tree consists of the following elements:

  e: a storage node elements
  left: for storing a left subtree
  right: for storing a right subtree
  color: the flag for the node color, red or black node

Code defines the red-black tree:

 type RBT struct {
    root    *RBTNode
    size    int
    compare Comparable
 }

 type RBTNode struct {
    e     interface{}
    left  *RBTNode
    right *RBTNode
    color bool
 }

The characteristics of the red-black tree, defined found:
  1, the size of the red-black tree that is N does not exceed the height 2logN
  2, is inserted in the worst case, to find the time complexity of the elements: 2logN
  . 3, insert the average case, find an element the average complexity: logN

  Here only a brief introduction to the concepts red-black tree, red-black tree realize the following detailed analysis of the code from the perspective of implementation;

Guess you like

Origin www.cnblogs.com/softlin/p/11069141.html