Skip to main content

Data Structures MCQs with Answers

Practice important Data Structures MCQs with answers and explanations.

Multiple Choice Questions

Q211: What does the left(p) function return in a binary tree?
  • A: Pointer to the right sub-tree
  • B: Pointer to the left sub-tree
  • C: The parent node
  • D: The contents of the node
View Answer
B

Q212: What is the main advantage of using a binary tree over a linked list for searching?
  • A: More memory usage
  • B: Faster insertion of elements
  • C: Fewer comparisons needed for search
  • D: Better handling of dynamic data sizes
View Answer
C

Q213: What is the role of the setLeft(p, x) function in a binary tree?
  • A: Sets the value of the right child node
  • B: Creates the left child node with value x
  • C: Retrieves the left child node
  • D: Deletes the left child node
View Answer
B

Q214: In the provided C++ code, which method is used to insert a new node into the binary tree?
  • A: getLeft()
  • B: insert()
  • C: setInfo()
  • D: getRight()
View Answer
B

Q215: What does the insert() function do when it encounters a duplicate value?
  • A: Deletes the node and continues
  • B: Displays a message and skips insertion
  • C: Inserts the node as a new child
  • D: Updates the existing node's value
View Answer
B

Q216: How does the insert() function determine where to place a new node in the tree?
  • A: By checking if the new value is less than or greater than the current node’s value
  • B: By a random decision
  • C: By comparing the new value with the root only
  • D: By counting the number of nodes in the tree
View Answer
A

Q217: What is the purpose of the TreeNode constructor that takes an Object * parameter?
  • A: Initializes the left child
  • B: Initializes the right child
  • C: Sets the value of the node
  • D: Sets the tree structure
View Answer
C

Q218: What does the getInfo() method of the TreeNode class return?
  • A: The left sub-tree
  • B: The right sub-tree
  • C: The value stored in the node
  • D: The parent node
View Answer
C

Q219: In the insert() function, what happens when the q pointer becomes NULL?
  • A: The node is inserted as the left child
  • B: The node is deleted
  • C: The node is inserted as the right child
  • D: The function exits
View Answer
C

Q220: How is the binary tree constructed from the list in the provided C++ code?
  • A: By randomly placing values
  • B: By using a predefined tree structure
  • C: By comparing and inserting values in order
  • D: By sorting the list before insertion
View Answer
C

Test Your Knowledge

Take a timed quiz on Data Structures

🚀 Start Quiz Now