Data Structures MCQs with Answers
Practice important Data Structures MCQs with answers and explanations.
Multiple Choice Questions
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
View Answer
A
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
View Answer
A
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
View Answer
A
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
View Answer
B
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
View Answer
A
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
View Answer
A
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
View Answer
C
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
View Answer
C
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
View Answer
B
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
View Answer
C