24 Lecture

CS301

Midterm & Final Term Short Notes

Deletion in AVL Tree

Deletion in AVL trees is the process of removing a node from the tree while maintaining the AVL property. Deletion in AVL trees requires a series of rotations to rebalance the tree and maintain its height-balance property. The process of deletio


Important Mcq's
Midterm & Finalterm Prepration
Past papers included

Download PDF
  1. What is the time complexity of deleting a node in an AVL tree? a) O(n) b) O(log n) c) O(h) d) O(h log n) Answer: c) O(h)

  2. Which case is checked for rebalancing the AVL tree after a node is deleted? a) Left-Left b) Left-Right c) Right-Right d) Right-Left Answer: d) Right-Left

  3. In an AVL tree, what is the maximum number of rotations needed to rebalance the tree after deleting a node? a) 1 b) 2 c) 3 d) 4 Answer: b) 2

  4. Which of the following statements is true for the AVL tree? a) AVL tree is a binary search tree b) AVL tree is a self-balancing binary search tree c) AVL tree is not a binary search tree d) AVL tree is a balanced binary search tree Answer: b) AVL tree is a self-balancing binary search tree

  5. What is the height of an AVL tree after deleting a node? a) Remains the same b) Decreases by 1 c) Increases by 1 d) Cannot be determined Answer: a) Remains the same

  6. Which of the following rotations is performed when deleting a node in the Right-Right case? a) Single left rotation b) Single right rotation c) Double left rotation d) Double right rotation Answer: b) Single right rotation

  7. Which of the following rotations is performed when deleting a node in the Left-Right case? a) Single left rotation b) Single right rotation c) Double left rotation d) Double right rotation Answer: d) Double right rotation

  8. Which of the following is a disadvantage of using AVL trees? a) Faster insertion and deletion operations b) Slow search operation c) More memory space required d) Cannot be used to implement balanced search trees Answer: c) More memory space required

  9. Which of the following is an advantage of using AVL trees? a) Lower time complexity for all operations b) Smaller tree height compared to other self-balancing trees c) Can handle unbalanced trees efficiently d) No need for tree balancing operations Answer: b) Smaller tree height compared to other self-balancing trees

  10. In which of the following cases is no rotation needed when deleting a node in an AVL tree? a) Left-Left case b) Left-Right case c) Right-Right case d) Right-Left case Answer: c) Right-Right case



Subjective Short Notes
Midterm & Finalterm Prepration
Past papers included

Download PDF
  1. What is AVL Tree? Describe the steps to delete a node in AVL Tree.

Answer: AVL Tree is a self-balancing binary search tree in which the height of the left and right subtrees of any node differs by at most one. To delete a node in an AVL Tree, we perform the following steps:

  1. Perform the standard BST delete operation for the node to be deleted.

  2. Check the balance factor of all the nodes in the path from the deleted node to the root.

  3. If the balance factor of any node becomes +2 or -2, perform the appropriate rotation to balance the tree.

  4. What is the difference between the deletion of a node in a BST and AVL Tree?

Answer: The deletion of a node in a BST can lead to an unbalanced tree, while in AVL Tree, after the deletion of a node, the balance factor of all the nodes is checked, and the tree is rebalanced by performing appropriate rotations.

  1. What are the different cases that can arise while deleting a node from an AVL Tree?

Answer: The different cases that can arise while deleting a node from an AVL Tree are:

  1. The node to be deleted is a leaf node.

  2. The node to be deleted has only one child.

  3. The node to be deleted has two children.

  4. How is the height of a node in an AVL Tree calculated?

Answer: The height of a node in an AVL Tree is calculated as the maximum height of its left and right subtrees plus one.

  1. Why is AVL Tree preferred over other binary search trees?

Answer: AVL Tree is preferred over other binary search trees because it is self-balancing, which ensures that the height of the tree remains balanced, and the search, insertion, and deletion operations take O(log n) time complexity.

  1. How is the balance factor of a node in an AVL Tree calculated?

Answer: The balance factor of a node in an AVL Tree is calculated as the difference between the height of its left and right subtrees.

  1. What is the role of rotations in AVL Tree?

Answer: Rotations are performed in an AVL Tree to balance the tree after insertion or deletion of a node. There are four types of rotations: left-rotate, right-rotate, left-right-rotate, and right-left-rotate.

  1. How is the balance of an AVL Tree maintained?

Answer: The balance of an AVL Tree is maintained by keeping the height difference of the left and right subtrees of each node within the range of -1 to +1. If the balance factor of a node becomes -2 or +2, appropriate rotations are performed to balance the tree.

  1. What are the advantages of AVL Tree?

Answer: The advantages of AVL Tree are:

  1. It ensures that the height of the tree is balanced.

  2. Search, insertion, and deletion operations take O(log n) time complexity.

  3. It is efficient in terms of time and space complexity.

  4. What is the worst-case time complexity of the deletion operation in an AVL Tree?

Answer: The worst-case time complexity of the deletion operation in an AVL Tree is O(log n).

Deletion in an AVL tree is similar to deletion in a binary search tree, with additional rebalancing steps to maintain the balance factor of the tree. The steps involved in deleting a node in an AVL tree are:
  1. Find the node to be deleted
  2. If the node is a leaf node, simply delete it
  3. If the node has only one child, replace the node with its child
  4. If the node has two children, find its successor (or predecessor), copy its value to the node to be deleted, and delete the successor (or predecessor) node
  5. After the node is deleted, check the balance factor of its parent node and perform the necessary rotations to rebalance the tree.
The rotations required to rebalance the tree after deletion depend on the balance factor of the nodes in the path from the deleted node to the root. If the balance factor of a node becomes -2 or 2 after deletion, the following rotations can be performed:
  1. Left-Left (LL) rotation
  2. Left-Right (LR) rotation
  3. Right-Right (RR) rotation
  4. Right-Left (RL) rotation
The choice of rotation depends on the balance factor of the nodes in the path from the deleted node to the root. The aim of the rotations is to bring the balance factor of the nodes back to -1, 0, or 1, which ensures that the height of the tree is logarithmic and the search time is efficient. Deletion in an AVL tree requires careful consideration of the balance factor and the choice of rotations to ensure that the tree remains balanced and efficient for search operations.