Data Structures MCQs with Answers
Practice important Data Structures MCQs with answers and explanations.
Chapter: 23
Q381:
What is the main purpose of single right rotation in an AVL tree?
A. Increase the height of the tree
B. Balance the tree after deletion
C. Rebalance the tree after insertion
D. Improve tree traversal efficiency
Correct Answer:
C
Chapter: 23
Q382:
What is the first step in the single right rotation process?
A. Set the new root node
B. Set the left child of k2 to k1's right
C. Set the right child of k1 to k2
D. Set k2 as right child of k1
Correct Answer:
B
Chapter: 23
Q383:
After a single right rotation, which node becomes the new root?
A. k1
B. k2
C. k3
D. k4
Correct Answer:
B
Chapter: 23
Q384:
In single left rotation, which node becomes the new root?
A. k1
B. k2
C. k3
D. k4
Correct Answer:
B
Chapter: 23
Q385:
What is the purpose of the height function in AVL tree rotations?
A. Calculate tree depth
B. Set node height based on subtrees
C. Update node height after rotation
D. Rebalance the tree
Correct Answer:
C
Chapter: 23
Q386:
Which rotation is performed first in a double right-left rotation?
A. Single right rotation
B. Single left rotation
C. Double right rotation
D. Double left rotation
Correct Answer:
A
Chapter: 23
Q387:
In a double left-right rotation, which rotation is applied first?
A. Single left rotation
B. Single right rotation
C. Double left-right rotation
D. Double right-left rotation
Correct Answer:
A
Chapter: 23
Q388:
When deleting a node from an AVL tree, how many rotations might be needed in the worst case?
A. 1
B. log2 N
C. N
D. 2
Correct Answer:
B
Chapter: 23
Q389:
What is the primary reason for needing multiple rotations during deletion in an AVL tree?
A. To improve search efficiency
B. To rebalance the tree
C. To increase the tree height
D. To reduce tree nodes
Correct Answer:
B
Chapter: 23
Q390:
In the deletion process of an AVL tree, what is the maximum number of rotations needed?
A. log2 N
B. 1
C. 2
D. 3
Correct Answer:
A
Chapter: 23
Q391:
What does the code k1->setRight(k2->getLeft()) in single left rotation accomplish?
A. Sets k1’s right child to k2's left
B. Sets k1’s left child to k2’s right
C. Sets k2’s left child to k1’s right
D. Sets k2’s right child to k1’s left
Correct Answer:
A
Chapter: 23
Q392:
In the single right rotation code, what does k1->setRight(k2) do?
A. Sets k2 as the right child of k1
B. Sets k1 as the right child of k2
C. Reassigns k1's left subtree
D. Updates the height of k1
Correct Answer:
A
Chapter: 23
Q393:
What happens to the heights of nodes after a single right rotation?
A. They are recalculated
B. They remain unchanged
C. They are set to zero
D. They are doubled
Correct Answer:
A
Chapter: 23
Q394:
What is the result of performing a single left rotation on a tree?
A. The right child becomes the root
B. The left child becomes the root
C. The tree height increases
D. The left child of the root moves up
Correct Answer:
B
Chapter: 23
Q395:
What type of tree structure is being discussed in the content?
A. AVL Tree
B. Binary Search Tree
C. Red-Black Tree
D. B-Tree
Correct Answer:
A
Chapter: 23
Q396:
When deleting a node in an AVL tree, how is the tree rebalanced if needed?
A. By single or double rotations
B. By restructuring the nodes
C. By updating the node values
D. By balancing the node heights
Correct Answer:
A
Chapter: 24
Q397:
What is the primary action taken when deleting a node from an AVL tree where the parent node has a balance of 0 and the node was deleted from the parent's left subtree?
A. Change the balance of the parent node and perform a double rotation
B. Change the balance of the parent node and perform a single rotation
C. Change the balance of the parent node and stop
D. No change needed to the balance of the parent node
Correct Answer:
C
Chapter: 24
Q398:
What happens when a node is deleted from the right subtree of a node with a balance of 0 in an AVL tree?
A. Perform a double rotation
B. Perform a single rotation
C. Change the balance of the parent node and stop
D. No change is needed
Correct Answer:
C
Chapter: 24
Q399:
What is the next step if deleting a node from an AVL tree causes a balance factor of -1 in a parent node's left subtree where the right subtree is unbalanced?
A. Perform a single rotation at the parent node
B. Perform a double rotation at the parent node
C. Change the balance of the parent node and stop
D. No rotation needed
Correct Answer:
B
Chapter: 24
Q400:
In AVL tree deletion, what is the action required when a node is deleted from a subtree of a node with a balance of 1 and the node was deleted from the parent’s left subtree?
A. Perform a double rotation
B. Perform a single rotation
C. Change the balance of the parent node and continue up the tree
D. Change the balance of the parent node and stop
Correct Answer:
C