# Data Structures: Question Set – 23

#### What is a rotation in an AVL tree?

A rotation in an AVL tree is an operation that changes the structure of the tree while maintaining the AVL property. There are two types of rotations: left rotation and right rotation.

#### How is a left rotation performed in an AVL tree?

A left rotation in an AVL tree is performed by moving the right child of a node up to the node’s position and moving the node down to the left of its former right child.

#### How is a right rotation performed in an AVL tree?

A right rotation in an AVL tree is performed by moving the left child of a node up to the node’s position and moving the node down to the right of its former left child.

#### How are AVL trees different from binary search trees?

AVL trees are different from binary search trees in that they maintain a balance property, which ensures that the height of the tree remains logarithmic in the number of nodes. Binary search trees do not have any balancing property, which means that their height can become linear in the number of nodes in the worst case.

#### What is the AVL tree deletion algorithm?

The AVL tree deletion algorithm is a modification of the standard binary search tree deletion algorithm that rebalances the tree after each deletion to maintain the AVL property. It involves finding the node to be deleted, replacing it with its successor or predecessor (depending on whether it has a left child or a right child), and then rebalancing the tree.

#### What is the AVL tree insertion algorithm?

The AVL tree insertion algorithm is a modification of the standard binary search tree insertion algorithm that rebalances the tree after each insertion to maintain the AVL property. It involves finding the appropriate position for the new node, inserting the node into the tree, and then rebalancing the tree.

#### What is the AVL tree balancing condition?

The AVL tree balancing condition states that for every node in the tree, the absolute value of the difference between the heights of its left and right subtrees (i.e., the balance factor) must be no greater than 1.

#### What is the worst-case time complexity for performing a sequence of m insertions and deletions in an AVL tree?

The worst-case time complexity for performing a sequence of m insertions and deletions in an AVL tree is O(mlog n), where n is the number of nodes in the tree.

#### Can an AVL tree have duplicate keys?

No, an AVL tree cannot have duplicate keys because it is a binary search tree, and binary search trees must maintain the property that each node has a unique key.

#### What is the difference between a red-black tree and an AVL tree?

The main difference between a red-black tree and an AVL tree is the balancing mechanism. While AVL trees maintain balance by ensuring that the heights of the left and right subtrees differ by at most one, red-black trees maintain balance by coloring nodes red or black and ensuring that no path from the root to a leaf has more than twice as many black nodes as any other path. As a result, red-black trees are generally more flexible and faster to rebalance than AVL trees, but they can have larger heights and use more memory.