Balanced binary tree and red black tree worst case analysis1. Classic Balanced binary treeThe Balanced binary tree (also known as the AVL tree) is a two-fork search tree with equilibrium conditions, with the most common theorem: a balanced binary tree is a two-fork lookup tree with a maximum height difference of 1 for each node of the Saozi right subtree . Becau
The red/black tree is a self-balancing binary search tree. It is a data structure used in computer science. A typical application is to implement correlated arrays. It was invented by Rochelle bell in 1972. It is called the "symmetric Binary Tree" and Its Modern name isLeo J. guibas and RobertSedgewick was obtained in a paper written in 1978. It is complex, but its operation has a good run time in the worst
basically balanced. Some Tree operations, such as insert, delete, and search, are proportional to the height of the tree in the worst case, therefore, the height limit of this tree makes the red and black trees highly efficient in the worst case, unlike the ordinary Binary Search Tree (BST ).
Conclusion 2:Height of th
inserted in the two-fork lookup tree (where the new node is inserted at the leaf node) and painted red. Then redraw its color or rotate to maintain the nature of the red-black tree, the adjustment is divided into the following three kinds of situations:1 new node n does not have a parent node (that is, at the root)paints the new node n as
tree is balanced before the node is inserted, it can be concluded that the grandfather node G must exist (rule 1: The root node has to be black), and is black (rule 2: There will be no contiguous red nodes), and the Uncle node U color is uncertain, so the problem can be divided into two categories:1, the Uncle node is black
the red case. Because the delete is successor just replaces the position of node, but the color is changed to node's color. In addition, if successor is not the right child of node, then you need to first replace the successor right child Successor->right successor, if successor is red, then successor-> Right is definitely b
(O (log n)) of color changes (actually very fast) and no more than three tree rotations (two times for the insert operation). While insertions and deletions are complex, the operation time can still be maintained at O (log n) times.Insert operationWe first increment the node with a two-fork look-up tree and mark it as red. (If set to black, it will lead to the path of the root to the leaf, there is an addi
violate at most one point at a time.There are 3 cases where the red-black tree is adjusted after inserting a junction Z.Situation 1. The tertiary node y of z is red.The new node inserted in the left image Z is a red node, its parent node A is red, violates the nature of 4, so it needs to be adjusted (because the node
down these two pictures of the situation.
in this case, as long as the replacement R is dyed black, it is ensured that rule 4 is not affected . The reason is that, from the tree structure before the delete operation is visible, this part contains a point pointing to the virtual edge of the red node, the previous article said that this kind of virtual edge is n
after deletion, you also need a series of processing to make the whole tree into a red black tree.Third, the red and black tree removal processRed and black tree deletion algorithm mainly has three steps3.1 Find the node to be deleted, this is a binary search tree lookup pr
1. What is a red-black tree (1) Introduction In the previous article, we introduced a two-fork search tree with a basic dynamic set operating time complexity of O (h). Unfortunately, these collection operations are faster when the binary search tree height is low, which means that when the height of the tree is high (or even if the tree becomes a 1 chain), the collection operations are not faster than exec
Red and black TreesThe red-black tree is a two-fork lookup tree , but adds a storage bit to the node's color at each node, either red or black. By limiting the shading of any one path from the root to the leaf,The
This article address: http://blog.csdn.net/cyp331203/article/details/42677833
Author: Bitter _ Coffee
Welcome reprint, but reprint please indicate the source, otherwise will investigate the corresponding responsibility, thank you.
The red-black tree is built on the basis of the two-fork Lookup tree, the binary lookup tree can see the "Introduction to the algorithm" binary search tree insertion and deletio
the balance factor. For a rotation animation demonstration, see Flash Animation in aVL:
Http://www.cnblogs.com/abatei/archive/2008/11/17/1335031.htmlInsert nodes on the red/black tree
Before discussing the insert operation of the red/black tree, you must understand that the initial color of any new node to be inserted
In the RB-DELETE, when y is black, the RB-DELETE-FIXUP function is called to adjust the color of the Red-black tree, which means that if y is red, there is no need to adjust it, next we will prove the correctness of this proposition.
First, the properties of the red and
two sons. Then, identify its successor, and then copy the contents of its successor to the content of that node, and then delete its successor. Here, the successor node is equivalent to the alias, after the contents of the successor node are copied to the "Deleted node", then the successor node is deleted. This subtly transforms the problem into a "delete successor" scenario, and the following is considered for subsequent nodes. In the case of a "del
This address:http://blog.csdn.net/cyp331203/article/details/42677833Bitter _ CoffeeWelcome reprint, but reproduced please indicate the source, otherwise will be held responsible, thank you!.The red-black tree is based on a two-fork search tree, which can be found in the "Introduction to Algorithm" binary search tree insertion and deletion and the "Introduction to the algorithm" binary tree in the pre-and po
The red-black tree is a self-balancing binary lookup tree that has the complexity of finding, inserting, and deleting O (log2n) In the worst case scenario. The longest path from the root node to any leaf node in a red-black tree does not exceed twice times the shortest path
Before we learned the binary search tree, we found that in some cases its height is not very uniform, and sometimes degenerate into a long chain, so we refer to some "balanced" two-fork search tree. The red and black tree is a "balanced" two-fork search tree, which ensures that in the worst case, the time complexity of the basic dynamic set operation is O (NLGN)
(N)-> right;ElseReturn grandparent (N)-> left;}
Ii. Situations of red/Black Tree InsertionScenario 1: The new node N is located on the root of the tree and has no parent node.Void insert_case1 (node N ){If (n-> parent = NULL)N-> color = black;ElseInsert_case2 (N );}
Case 2: the parent node P of the new node is black
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.