22 Lecture

CS301

Midterm & Final Term Short Notes

Cases of rotations

Rotations in a binary search tree are used to maintain balance and ensure efficient operations. There are two types of rotations: left rotations and right rotations. Each type of rotation has two cases: single rotations and double rotations. Sin


Important Mcq's
Midterm & Finalterm Prepration
Past papers included

Download PDF
  1. Which of the following is not a type of rotation in a binary search tree? A. Left rotation B. Right rotation C. Upward rotation D. Double rotation Answer: C

  2. When is a single left rotation used in a binary search tree? A. When the imbalance occurs in the immediate left child B. When the imbalance occurs in the immediate right child C. When the imbalance occurs in the grandchild of the left child D. When the imbalance occurs in the grandchild of the right child Answer: A

  3. Which of the following is a case of double rotation in a binary search tree? A. Left-Left case B. Left-Right case C. Right-Left case D. Right-Right case Answer: B

  4. In a left-right double rotation, what is the first step performed? A. A single left rotation on the right child B. A single right rotation on the left child C. A double right rotation on the left child D. A double left rotation on the right child Answer: B

  5. Which of the following is not a benefit of rotations in a binary search tree? A. Maintaining balance B. Ensuring efficient search operations C. Reducing the height of the tree D. Increasing the height of the tree Answer: D

  6. What is the maximum number of rotations required to balance a node in a binary search tree? A. 1 B. 2 C. 3 D. 4 Answer: B

  7. When is a single right rotation used in a binary search tree? A. When the imbalance occurs in the immediate left child B. When the imbalance occurs in the immediate right child C. When the imbalance occurs in the grandchild of the left child D. When the imbalance occurs in the grandchild of the right child Answer: B

  8. Which of the following is a case of single rotation in a binary search tree? A. Left-Left case B. Left-Right case C. Right-Left case D. Right-Right case Answer: A

  9. In a left-left single rotation, what is the new root of the subtree? A. The left child of the original root B. The right child of the original root C. The parent of the original root D. The original root itself Answer: A

  10. Which of the following is a disadvantage of using rotations in a binary search tree? A. Increased tree height B. Reduced search efficiency C. Increased complexity D. None of the above Answer: D



Subjective Short Notes
Midterm & Finalterm Prepration
Past papers included

Download PDF
  1. What is a rotation in a binary search tree? Answer: A rotation is a manipulation performed on a binary search tree to maintain its balance.

  2. What are the two types of rotations in a binary search tree? Answer: The two types of rotations are single rotations and double rotations.

  3. How do rotations help in balancing a binary search tree? Answer: Rotations help in redistributing the nodes of a binary search tree to maintain balance, which in turn helps in efficient search operations.

  4. When is a single left rotation used in a binary search tree? Answer: A single left rotation is used when the imbalance occurs in the immediate left child of a node.

  5. When is a single right rotation used in a binary search tree? Answer: A single right rotation is used when the imbalance occurs in the immediate right child of a node.

  6. What is the difference between a single rotation and a double rotation in a binary search tree? Answer: A single rotation involves rotating only one node, while a double rotation involves rotating two nodes.

  7. What is the maximum number of rotations required to balance a node in a binary search tree? Answer: The maximum number of rotations required to balance a node in a binary search tree is two.

  8. What is the left-right case in a binary search tree rotation? Answer: The left-right case occurs when the left child of a node has a right child, and the subtree is imbalanced.

  9. What is the right-left case in a binary search tree rotation? Answer: The right-left case occurs when the right child of a node has a left child, and the subtree is imbalanced.

  10. What is the purpose of using rotations in a binary search tree? Answer: The purpose of using rotations in a binary search tree is to maintain its balance and ensure efficient search operations.

Rotations are operations performed on binary search trees to maintain balance and ensure efficient search operations. There are two types of rotations: single rotations and double rotations. A single rotation involves rotating only one node, while a double rotation involves rotating two nodes. In a binary search tree, a single left rotation is used when the imbalance occurs in the immediate left child of a node. A single right rotation is used when the imbalance occurs in the immediate right child of a node. The maximum number of rotations required to balance a node in a binary search tree is two. In addition to single rotations, double rotations are also used in some cases. The left-right case occurs when the left child of a node has a right child, and the subtree is imbalanced. In this case, a double rotation involving a left rotation followed by a right rotation is used. The right-left case occurs when the right child of a node has a left child, and the subtree is imbalanced. In this case, a double rotation involving a right rotation followed by a left rotation is used. The main purpose of using rotations in a binary search tree is to maintain its balance and ensure efficient search operations. Balancing a binary search tree is important because an unbalanced tree can result in longer search times and slower overall performance. By performing rotations as needed, a binary search tree can maintain balance and provide faster search times, making it a useful data structure for a wide range of applications.