Skip to main content

Data Structures MCQs with Answers

Practice important Data Structures MCQs with answers and explanations.

Chapter: 15
Q261:
Which method is used to print nodes of a binary search tree in sorted order?
A. Preorder
B. Postorder
C. Inorder
D. Level-order
Correct Answer: C
Chapter: 15
Q262:
How does the insert function handle duplicate strings in a binary search tree?
A. It replaces the existing node with the new node
B. It increments a counter for duplicates
C. It displays a message and deletes the new node
D. It skips the insertion of the duplicate string
Correct Answer: C
Chapter: 15
Q263:
When deleting a node with two children from a BST, what is the next step after finding the in-order successor?
A. Replace the node with the in-order successor and delete the successor node
B. Delete the node and its left child
C. Replace the node with the in-order predecessor and delete the predecessor node
D. Simply delete the node without further actions
Correct Answer: A
Chapter: 15
Q264:
What is the first step when deleting a leaf node from a BST?
A. Replace it with its right child
B. Remove it from the tree
C. Replace it with its left child
D. Adjust its parent's pointer to NULL
Correct Answer: B
Chapter: 15
Q265:
In the wordTree function, what is the role of the inorder function?
A. To insert new nodes into the BST
B. To delete nodes from the BST
C. To print the nodes of the BST in sorted order
D. To check for duplicate nodes
Correct Answer: C
Chapter: 15
Q266:
In a binary search tree, what does an in-order traversal produce?
A. Nodes sorted in descending order
B. Nodes sorted in random order
C. Nodes sorted in ascending order
D. Nodes sorted by level
Correct Answer: C
Chapter: 15
Q267:
Which of the following statements is true about the delete method for a node with one child?
A. The node is deleted and its child becomes the new child of the node’s parent
B. The node is deleted and the parent is updated to point to NULL
C. The node’s child is promoted to its parent’s position
D. The node’s parent is deleted and its child takes its place
Correct Answer: A
Chapter: 15
Q268:
How does the insert method determine whether to traverse left or right in a BST with strings?
A. By comparing ASCII values of the first character of each string
B. By comparing the lengths of the strings
C. By using the strcmp() function to compare the entire strings
D. By checking the length of the longest string
Correct Answer: C
Chapter: 15
Q269:
What is the output of the inorder traversal of a binary search tree?
A. Nodes in the order they were inserted
B. Nodes in level order
C. Nodes sorted in ascending order
D. Nodes sorted in descending order
Correct Answer: C
Chapter: 15
Q270:
In the delete method, what is the role of the in-order successor when deleting a node with two children?
A. To replace the node to be deleted and then delete the successor node
B. To replace the node to be deleted with its left child
C. To replace the node to be deleted with its right child
D. To adjust the parent node’s pointer to the successor node
Correct Answer: A
Chapter: 16
Q271:
What is Case I in deleting a node from a Binary Search Tree (BST)?
A. Node has one child
B. Node is a leaf node
C. Node has two children
D. Node has no children
Correct Answer: B
Chapter: 16
Q272:
In Case II of deleting a node from a BST, what should you do if the node has one child?
A. Replace it with the child node
B. Replace it with the parent node
C. Replace it with the inorder successor
D. Do nothing
Correct Answer: A
Chapter: 16
Q273:
What is the key step in Case III for deleting a node with two children in a BST?
A. Delete the node directly
B. Replace with the inorder successor
C. Replace with the maximum node in the left subtree
D. Replace with the minimum node in the left subtree
Correct Answer: B
Chapter: 16
Q274:
What does the findMin method return in a BST?
A. The maximum node
B. The root node
C. The minimum node
D. The inorder successor
Correct Answer: C
Chapter: 16
Q275:
What is the role of the remove method in the BST C++ code?
A. To remove nodes from the tree
B. To add nodes to the tree
C. To search for nodes in the tree
D. To replace nodes in the tree
Correct Answer: A
Chapter: 16
Q276:
What happens when cmp is less than 0 in the remove method?
A. The node is in the right subtree
B. The node is in the left subtree
C. The node is at the root
D. The node is not in the tree
Correct Answer: B
Chapter: 16
Q277:
What is the purpose of the findMin method in BST deletion?
A. To find the maximum node in the tree
B. To find the minimum node in the tree
C. To find the parent of the node
D. To find the inorder predecessor
Correct Answer: B
Chapter: 16
Q278:
What should be done if a node with both children is to be deleted in a BST?
A. Replace it with the parent node
B. Replace it with the maximum node in the right subtree
C. Replace it with the inorder successor
D. Replace it with the root node
Correct Answer: C
Chapter: 16
Q279:
In the remove method, what happens when the node to be deleted is a leaf node?
A. It is removed directly
B. It is replaced with the right child
C. It is replaced with the left child
D. It is replaced with the inorder successor
Correct Answer: A
Chapter: 16
Q280:
How does the findMin method work recursively in a BST?
A. It searches the right subtree
B. It searches the left subtree
C. It searches all nodes
D. It searches the parent node
Correct Answer: B

Test Your Knowledge

Take a timed quiz on Data Structures

🚀 Start Quiz Now