20 Lecture

CS301

Midterm & Final Term Short Notes

AVL Tree

AVL Tree is a self-balancing binary search tree where the difference between the height of the left and right subtrees cannot be more than one for all nodes. It provides faster operations for search, insertion, and deletion compared to other sel


Important Mcq's
Midterm & Finalterm Prepration
Past papers included

Download PDF
  1. What is AVL Tree? a) Binary Tree b) Self-balancing Binary Search Tree c) Hash Tree d) None of the above

Answer: b) Self-balancing Binary Search Tree

  1. In AVL Tree, what is the maximum difference between the height of the left and right subtrees? a) 1 b) 2 c) 3 d) 4

Answer: a) 1

  1. What is the time complexity of search operation in AVL Tree? a) O(log n) b) O(n) c) O(n log n) d) O(1)

Answer: a) O(log n)

  1. In AVL Tree, what operation is performed to balance the tree? a) Rotation b) Inversion c) Deletion d) None of the above

Answer: a) Rotation

  1. What is the worst-case time complexity of insertion operation in AVL Tree? a) O(log n) b) O(n) c) O(n log n) d) O(1)

Answer: a) O(log n)

  1. What is the height of an AVL Tree with n nodes in the worst-case scenario? a) log(n) b) log(n) + 1 c) 2log(n) d) 2log(n) + 1

Answer: b) log(n) + 1

  1. Which of the following statements is true about AVL Tree? a) AVL Tree is a balanced binary search tree b) AVL Tree is an unbalanced binary search tree c) AVL Tree is a type of heap data structure d) AVL Tree is a type of graph data structure

Answer: a) AVL Tree is a balanced binary search tree

  1. What is the time complexity of deletion operation in AVL Tree? a) O(log n) b) O(n) c) O(n log n) d) O(1)

Answer: a) O(log n)

  1. Which of the following is not a balancing rule in AVL Tree? a) Right-Right (RR) b) Left-Right (LR) c) Left-Left (LL) d) Right-Left (RL)

Answer: d) Right-Left (RL)

  1. Can AVL Tree have duplicate keys? a) Yes b) No

Answer: b) No



Subjective Short Notes
Midterm & Finalterm Prepration
Past papers included

Download PDF
  1. What is AVL Tree and what is its purpose? Answer: AVL Tree is a self-balancing binary search tree where the difference between the height of the left and right subtrees cannot be more than one for all nodes. Its purpose is to provide faster operations for search, insertion, and deletion compared to other self-balancing trees.

  2. What is the difference between AVL Tree and Red-Black Tree? Answer: Both AVL Tree and Red-Black Tree are self-balancing binary search trees. The main difference between them is that AVL Tree guarantees that the difference between the heights of left and right subtrees is at most one, whereas Red-Black Tree guarantees that the longest path from the root to a leaf is no more than twice as long as the shortest path.

  3. How does rotation help in balancing the AVL Tree? Answer: Rotation is the operation performed to balance the AVL Tree. It involves changing the structure of the tree by rotating a node to a new position, which helps to maintain the balance of the tree by keeping the height difference of the left and right subtrees at most one.

  4. What is the height of an AVL Tree with one node? Answer: The height of an AVL Tree with one node is 0.

  5. Can AVL Tree have duplicate keys? Answer: No, AVL Tree cannot have duplicate keys.

  6. What is the time complexity of search operation in AVL Tree? Answer: The time complexity of search operation in AVL Tree is O(log n).

  7. What is the worst-case time complexity of insertion operation in AVL Tree? Answer: The worst-case time complexity of insertion operation in AVL Tree is O(log n).

  8. How does AVL Tree maintain balance after a node is inserted or deleted? Answer: AVL Tree maintains balance by performing rotations after a node is inserted or deleted to ensure that the height difference of the left and right subtrees is at most one.

  9. What is the height of a perfectly balanced AVL Tree with 15 nodes? Answer: The height of a perfectly balanced AVL Tree with 15 nodes is 3.

  10. What is the purpose of AVL Tree being self-balancing? Answer: The purpose of AVL Tree being self-balancing is to ensure that the worst-case time complexity of operations like search, insertion, and deletion is O(log n), which is much faster than other non-balanced binary search trees.

AVL Tree is a self-balancing binary search tree where the difference between the height of the left and right subtrees cannot be more than one for all nodes. It is named after its inventors, Adelson-Velskii and Landis. The main advantage of an AVL Tree is that it provides faster search, insertion, and deletion operations compared to other non-balanced binary search trees like a regular binary search tree. The insertion and deletion operations in an AVL Tree are similar to a regular binary search tree. However, the AVL Tree maintains balance by performing rotations after an insertion or deletion operation to ensure that the height difference of the left and right subtrees is at most one. The four types of rotations are: left rotation, right rotation, left-right rotation, and right-left rotation. The time complexity of search, insertion, and deletion operations in an AVL Tree is O(log n) in the worst case scenario, where n is the number of nodes in the tree. This is because the height of the tree is always maintained as log(n). AVL Tree has some limitations as well. It requires additional memory to store the balance factor for each node, which can be a problem for large datasets. Also, the rotations required to maintain balance can be time-consuming, making it less efficient for smaller datasets. In conclusion, AVL Tree is a popular choice for applications where efficient search, insertion, and deletion operations are crucial, and the number of nodes in the dataset is moderate to large. The self-balancing feature ensures that the height of the tree is maintained, providing faster operations than non-balanced trees.