RR RotationIf the node is inserted into the right of the right sub-tree of a node A and the tree becomes unbalanced then, in that case, RR rotation will be performed as shown in the following diagram. While the rotation, the node B becomes the root node of the tree. The critical node A will be moved to its left and becomes the left child of B. The sub-tree T3 becomes the right sub-tree of A. T1 and T2 becomes the left and right sub-tree of node A. ![]() ExampleInsert 90 into the AVL Tree shown in the figure. ![]() Solution :90 is inserted in to the right of the right sub-tree. In this case, critical node A will be 85, which is the closest ancestor to the new node, whose balance factor is disturbed. Therefore, we need to rebalance the tree by applying RR rotation onto it. The node B will be the node 90 , which will become the root node of this sub-tree. The critical node 85 will become its left child, in order to produce the rebalanced tree which is now an AVL tree. ![]()
Next TopicDoubly Linked List
|
JavaTpoint offers too many high quality services. Mail us on [email protected], to get more information about given services.
JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected]
Duration: 1 week to 2 week