Skip to main content

Data Structures MCQs with Answers

Practice important Data Structures MCQs with answers and explanations.

Chapter: 16
Q281:
What is indicated by a NULL return from the findMin method?
A. The tree is empty
B. The node is the maximum node
C. The node is the root
D. The tree is not fully traversed
Correct Answer: A
Chapter: 16
Q282:
What is the main advantage of using a template class for the BinarySearchTree?
A. It restricts the data type to integers
B. It allows the tree to store multiple data types
C. It simplifies the implementation
D. It avoids memory allocation issues
Correct Answer: B
Chapter: 16
Q283:
What does the elementAt method in the BST class do?
A. Returns the element of a node
B. Sets the element of a node
C. Finds the minimum element
D. Deletes a node from the tree
Correct Answer: A
Chapter: 16
Q284:
What does the printInorder method do in the BST?
A. Prints nodes in pre-order
B. Prints nodes in post-order
C. Prints nodes in in-order traversal
D. Prints nodes in level-order
Correct Answer: C
Chapter: 16
Q285:
How does the remove method handle a node with two children in its implementation?
A. By replacing it with the maximum node in the left subtree
B. By replacing it with the inorder predecessor
C. By deleting the node directly
D. By copying the node value to the parent
Correct Answer: B
Chapter: 16
Q286:
What does the findMax method return?
A. The maximum value in the tree
B. The minimum value in the tree
C. The root node
D. The inorder successor
Correct Answer: A
Chapter: 16
Q287:
What does the BinarySearchTree class's findMin() method return?
A. The largest item in the tree
B. The smallest item in the tree
C. A boolean indicating if the tree is empty
D. The root node of the tree
Correct Answer: B
Chapter: 16
Q288:
In the BinarySearchTree implementation, what happens when remove() is called on a node with two children?
A. The node is removed without any changes
B. The node is replaced with its parent
C. The node is replaced with the smallest item in its right subtree
D. The node is replaced with the largest item in its left subtree
Correct Answer: C
Chapter: 16
Q289:
Which of the following is true about the insert() method in the BinarySearchTree class?
A. It allows duplicate entries
B. It ignores duplicate entries
C. It replaces existing entries with new ones
D. It always inserts at the root node
Correct Answer: B
Chapter: 16
Q290:
What does the makeEmpty() method do in the BinarySearchTree class?
A. Prints all elements in the tree
B. Returns the root node of the tree
C. Deletes all nodes and makes the tree empty
D. Finds the maximum element in the tree
Correct Answer: C
Chapter: 16
Q291:
In the BinarySearchTree implementation, which method would you use to find the largest item?
A. findMin()
B. findMax()
C. find()
D. printTree()
Correct Answer: B
Chapter: 16
Q292:
What is the output of printTree() after removing all even numbers from a tree containing numbers 0 to 30?
A. 0, 2, 4, 6, 8, ..., 30
B. 1, 3, 5, 7, 9, ..., 29
C. 1, 2, 3, 4, 5, ..., 30
D. 2, 4, 6, 8, 10, ..., 30
Correct Answer: B
Chapter: 16
Q293:
What does the find() method return if the searched element is not found in the tree?
A. The element itself
B. NULL
C. ITEM_NOT_FOUND
D. The root of the tree
Correct Answer: C
Chapter: 16
Q294:
How does the clone() method in BinarySearchTree function?
A. It copies the tree structure without elements
B. It creates a new tree with the same elements as the original tree
C. It deletes the original tree and creates a new one
D. It creates a new tree with different elements
Correct Answer: B
Chapter: 16
Q295:
In the BinarySearchTree implementation, what is the purpose of the elementAt() method?
A. To find the largest item in the tree
B. To return the element field of a node or ITEM_NOT_FOUND if the node is NULL
C. To print the elements of the tree in sorted order
D. To remove an element from the tree
Correct Answer: B
Chapter: 16
Q296:
Which header file is included in the BinarySearchTree.cpp file?
A. #include <iostream.h>
B. #include <iostream>
C. #include "BinarySearchTree.h"
D. #include "BinarySearchTree.cpp"
Correct Answer: C
Chapter: 17
Q297:
What does the symbol & represent when used in front of a variable in C++?
A. Address operator
B. Bitwise AND operator
C. Logical AND operator
D. Reference operator
Correct Answer: A
Chapter: 17
Q298:
In the statement int* ptr = &x;, what does ptr store?
A. The value of x
B. The address of x
C. The type of x
D. The reference of x
Correct Answer: B
Chapter: 17
Q299:
What does the function intMinus1 do to the passed variable?
A. Decreases the value by 1 and returns the new value
B. Increases the value by 1 and returns the new value
C. Decreases the value by 2 and returns the new value
D. Increases the value by 2 and returns the new value
Correct Answer: A
Chapter: 17
Q300:
What is the purpose of using pointers in the function intMinus2?
A. To modify the original value of the variable
B. To create a new variable
C. To copy the value of the variable
D. To return a pointer to the variable
Correct Answer: A

Test Your Knowledge

Take a timed quiz on Data Structures

🚀 Start Quiz Now