Skip to main content

Data Structures MCQs with Answers

Practice important Data Structures MCQs with answers and explanations.

Multiple Choice Questions

Q221: Which function of the TreeNode class sets the right child pointer?
  • A: setRight()
  • B: setLeft()
  • C: getRight()
  • D: getLeft()
View Answer
A

Q222: How is the TreeNode class designed to handle different data types?
  • A: By using explicit type declarations
  • B: By using a template class
  • C: By using multiple inheritance
  • D: By using type casting
View Answer
B

Q223: What is the main advantage of using a binary search tree (BST) over a linked list for search operations?
  • A: Faster search times
  • B: More memory-efficient
  • C: Easier to implement
  • D: Simpler traversal
View Answer
A

Q224: In a binary search tree, where are nodes with values less than the root node placed?
  • A: Right subtree
  • B: Left subtree
  • C: Root node
  • D: None of the above
View Answer
B

Q225: What is the maximum number of comparisons required to find a number in a binary tree of depth 20?
  • A: 10
  • B: 20
  • C: 30
  • D: 40
View Answer
B

Q226: How is the depth ddd of a complete binary tree with nnn nodes calculated?
  • A: d=log⁡2(n)d = \log_2(n)d=log2​(n)
  • B: d=log⁡2(n+1)−1d = \log_2(n + 1) - 1d=log2​(n+1)−1
  • C: d=nlog⁡2(n)d = n \log_2(n)d=nlog2​(n)
  • D: d=n2d = \frac{n}{2}d=2n​
View Answer
B

Q227: What is the time complexity of searching in a linked list with nnn nodes?
  • A: O(log⁡n)O(\log n)O(logn)
  • B: O(n)O(n)O(n)
  • C: O(1)O(1)O(1)
  • D: O(nlog⁡n)O(n \log n)O(nlogn)
View Answer
B

Q228: What does the preorder traversal method in a binary tree do?
  • A: Prints the left subtree, then root, then right subtree
  • B: Prints the root, then left subtree, then right subtree
  • C: Prints the right subtree, then root, then left subtree
  • D: Prints the root, then right subtree, then left subtree
View Answer
B

Q229: In which traversal method are nodes printed in sorted order in a binary search tree?
  • A: Preorder
  • B: Inorder
  • C: Postorder
  • D: Level-order
View Answer
B

Q230: What will be the output of the inorder traversal of a binary search tree?
  • A: Nodes in reverse sorted order
  • B: Nodes in random order
  • C: Nodes in sorted order
  • D: Nodes in the order they were inserted
View Answer
C

Test Your Knowledge

Take a timed quiz on Data Structures

🚀 Start Quiz Now