Data Structures MCQs with Answers
Practice important Data Structures MCQs with answers and explanations.
Chapter: 19
Q341:
How does using the const keyword in a class method impact the method's interaction with class members?
A. The method can modify class members
B. The method cannot modify class members
C. The method can only read class members
D. The method must be static
Correct Answer:
B
Chapter: 19
Q342:
What is the result of inserting sorted data into a binary search tree?
A. The tree becomes balanced
B. The tree resembles a linked list
C. The tree will be a complete binary tree
D. The tree has fewer nodes than expected
Correct Answer:
B
Chapter: 20
Q343:
What is an AVL tree?
A. A type of binary tree
B. A type of linked list
C. A type of array
D. A type of stack
Correct Answer:
A
Chapter: 20
Q344:
What is the maximum height difference allowed between the left and right sub-trees in an AVL tree?
A. 2
B. 1
D. 3
Correct Answer:
B
Chapter: 20
Q345:
In an AVL tree, the balance factor of a node is defined as:
A. Height of right subtree minus height of left subtree
B. Height of left subtree minus height of right subtree
C. Height of left subtree plus height of right subtree
D. Height of right subtree plus height of left subtree
Correct Answer:
B
Chapter: 20
Q346:
How many levels are there in a binary tree with height 3?
A. 4
B. 3
C. 5
D. 2
Correct Answer:
A
Chapter: 20
Q347:
If a node has a balance factor of 2, what action is typically required?
A. No action required
B. Right rotation
C. Left rotation
D. Left-Right rotation
Correct Answer:
B
Chapter: 20
Q348:
When inserting a new node into an AVL tree, what happens if the balance factor of a node is -2?
A. Tree becomes unbalanced
B. Tree becomes balanced
C. Tree remains unchanged
D. Requires a left rotation
Correct Answer:
A
Chapter: 20
Q349:
In which scenario does an AVL tree require a left rotation?
A. When the right subtree is deeper
B. When the left subtree is deeper
C. When both subtrees are of equal height
D. When there is no subtree
Correct Answer:
B
Chapter: 20
Q350:
Which of the following figures represents an AVL tree?
A. Tree with nodes having balance factors outside -1, 0, 1
B. Tree where balance factors are -1, 0, 1
C. Tree with nodes not having balance factors
D. Tree with random heights
Correct Answer:
B
Chapter: 20
Q351:
After an insertion operation, if an AVL tree node has a balance factor of -2 and its right child has a balance factor of 1, which rotation is performed?
A. Left rotation
B. Right rotation
C. Left-Right rotation
D. Right-Left rotation
Correct Answer:
D
Chapter: 20
Q352:
When inserting node 3 into a tree where node 1 is the root and node 2 is its right child, what will be the new root if rotations are needed?
A. Node 1
B. Node 2
C. Node 3
D. Node 2 becomes root
Correct Answer:
B
Chapter: 20
Q353:
What does the AVL tree balance condition ensure after any insertion or deletion?
A. Nodes are always sorted
B. The tree remains balanced
C. All nodes have the same height
D. The tree is completely balanced
Correct Answer:
B
Chapter: 20
Q354:
In AVL trees, which node rearrangement is necessary when inserting a new node causes imbalance?
A. No rearrangement is needed
B. Only swapping node values
C. Rotation of nodes
D. Deletion of nodes
Correct Answer:
C
Chapter: 20
Q355:
What is the height of the right subtree of node 5 in the given AVL tree example if node 7 is the deepest node?
A. 2
B. 3
C. 1
D. 4
Correct Answer:
A
Chapter: 21
Q356:
What is the primary goal of balancing an AVL tree?
A. To ensure faster searching
B. To minimize memory usage
C. To maintain a balanced height
D. To reduce tree depth
Correct Answer:
C
Chapter: 21
Q357:
After inserting the number 4 in the AVL tree shown in Fig 21.3, which node requires rotation?
A. Node 1
B. Node 3
C. Node 2
D. Node 4
Correct Answer:
C
Chapter: 21
Q358:
In Fig 21.5, what is the new root node after performing the rotation?
A. Node 2
B. Node 3
C. Node 4
D. Node 5
Correct Answer:
C
Chapter: 21
Q359:
What is the result of the inorder traversal of the AVL tree after inserting nodes 1 to 7?
A. 1 2 3 4 5 6 7
B. 1 2 3 4 5 6
C. 1 3 2 4 5 6 7
D. 1 2 4 3 5 6 7
Correct Answer:
A
Chapter: 21
Q360:
Which node's insertion leads to case 1 rotation?
A. Insertion in the right subtree of the left child of α
B. Insertion in the left subtree of the right child of α
C. Insertion in the right subtree of the right child of α
D. Insertion in the left subtree of the left child of α
Correct Answer:
D