Posts

AVL Tree VS RB Tree with Application

Image
  In this blog, we will compare Red-Black Tree and AVL Tree.  Red-Black Tree Properties :    Self-Balancing is provided by painting each node with two colors(Red or Black). When the Tree is modified, a new tree is subsequently rearranged and repainted. It requires 1 bit of color information for each node in the tree. Time complexity: O(logn). Constraints  maintained by Red Black Tree :    The Root is always black. All NULL leaves are black, and both children of a red node are black. Every simple path from a given node to any of its descendant leaves contains the same number of black  nodes. The path from the Root to the farthest leaf is no more than twice as long as the path from the root to the nearest leaf. Time complexity: O(long).  AVL(Adelson-Velskii and Landis) Tree   Properties :    The height difference between the left and right subtree of the node should be less than 2. Re-balancing is done when the heights of two chi...