Open In App

Weak AVL or Rank Balanced Trees

Weak AVL trees, also known as rank-balanced trees, are a type of self-balancing binary search tree that aims to balance the tree while minimizing the number of rotations needed to maintain balance. These trees are similar to AVL trees in that they both use rotations to maintain balance, but they differ in how they define balance.

Explanation:

In an AVL tree, the height difference between the left and right subtrees of any node must not exceed 1. This means that the tree is very strictly balanced, with the left and right subtrees of each node having roughly the same height. While this ensures good balance and fast search times, it also means that AVL trees require a lot of rotations to maintain balance, especially when the tree is constantly being modified by inserting or deleting elements.



Properties of Weak AVL or Rank Balanced Trees:

Some of the key properties of weak AVL trees include:

How the tree is balanced?

In a weak AVL tree, a node is considered “weak” if the height difference between its left and right subtrees is greater than 1. If a node becomes weak, it is balanced by rotating its subtrees in a similar manner to a regular AVL tree.



There are two types of rotations that can be performed on a weak AVL tree: left rotations and right rotations

For example, consider the following weak AVL tree:

Example of Weak AVL Tree

The node with value 8 is weak because the height difference between its left and right subtrees is greater than 1. To balance this tree, we can perform a right rotation on the node with value 8:

Right rotation on the node with value 8

This rotates the subtree rooted at 8 to the right, and the subtree rooted at 6 to the left. This results in a balanced tree, with the height difference between the left and right subtrees of each node being less than or equal to 1.

Weak AVL trees are similar to regular AVL trees in that they are self-balancing, but they are less strict in their balancing criteria. This can make them faster to insert into and delete from, but at the cost of potentially lower performance for certain operations.

How to implement each of the update, insertion, deletion, and searching in the Weak AVL or Rank Balanced Trees:

Here is an approach for step-by-step implementing each of the update, insertion, deletion, and search operations in a weak AVL tree or ranked balanced tree, along with their complexities:

Update:

The complexity of the update operation is: O(log n)

Insertion:

The complexity of the  insertion operation is: O(log n)

Deletion:

The complexity of the deletion operation is: O(log n)

Searching:

The complexity of the search operation is: O(log n)

Complexity Analysis:

The time complexity of operations on a weak AVL tree or a rank-balanced tree depends on the specific operation being performed and the structure of the tree. In general, however, these trees have time complexities similar to those of regular AVL trees for most operations.

For example, the time complexity of inserting a new node into a weak AVL tree or a rank-balanced tree is typically O(log n), where n is the number of nodes in the tree. This is because these trees are self-balancing and maintain a logarithmic height, similar to regular AVL trees.0

Overall, the time complexity of operations on a weak AVL tree or a rank-balanced tree is similar to that of a regular AVL tree, but with potentially lower performance for certain operations due to the relaxed balancing criteria.

How does the rebalancing happen to Weak AVL or Rank Balanced Trees?

In a weak AVL tree or ranked balanced tree, rebalancing is performed using rotations. A rotation is a local operation that rearranges the nodes in the tree to restore balance. There are two types of rotations: left rotations and right rotations.

A left rotation is performed on a node that is right-heavy, meaning that the height of its right subtree is greater than the height of its left subtree. 

Right rotation is performed on a node that is left-heavy, meaning that the height of its left subtree is greater than the height of its right subtree. 

In a weak AVL tree or ranked balanced tree, rotations are used to maintain balance after insertions and deletions. When a new element is inserted into the tree, it may cause the tree to become unbalanced. To restore balance, the tree is traversed from the inserted node up to the root, and rotations are performed as needed to restore the balance conditions. Similarly, when an element is deleted from the tree, it may cause the tree to become unbalanced. In this case, rotations are also used to restore balance.

Here is an example of how rebalancing happens in a weak AVL tree or ranked balanced tree:

Suppose we have the following weak AVL tree:

Example of Weak AVL tree

Now suppose we want to insert element 13 into this tree. We first insert it as we would in a standard binary search tree, by finding the correct position for it based on its value. In this case, we would insert it as the right child of the node with value 12:

Insertion of 13 in WAVL Tree

Now the tree is no longer balanced, because the right subtree of the node with value 12 has a height of 2, while the left subtree has a height of 0. To restore balance, we perform a left rotation on the node with value 12:

Left Rotation on the WAVL Tree

Now the tree is balanced again because the height of the left and right subtrees of each node differ by at most 1.

The difference with a height-balanced tree:

A height-balanced tree is a type of self-balancing binary search tree in which the height difference between the left and right subtrees of any node is limited to a specific value, usually 1 or 2. This helps to ensure that the tree remains balanced, with a logarithmic height, which allows for efficient insertion, deletion, and search operations.


Article Tags :