Data Structures MCQs with Answers
Practice important Data Structures MCQs with answers and explanations.
Chapter: 13
Q241:
What does the postorder traversal method print last?
A. Root node
B. Left subtree
C. Right subtree
D. The entire tree
Correct Answer:
A
Chapter: 13
Q242:
What kind of data structure is a binary search tree?
A. Linear data structure
B. Non-linear data structure
C. Hash-based data structure
D. Array-based data structure
Correct Answer:
B
Chapter: 14
Q243:
What does a recursive function call use to manage execution flow?
A. Queue
B. Stack
C. Array
D. List
Correct Answer:
B
Chapter: 14
Q244:
What is the first step in the preorder traversal of a binary tree?
A. Print the value of the node
B. Traverse the left subtree
C. Traverse the right subtree
D. Check if the node is NULL
Correct Answer:
A
Chapter: 14
Q245:
Which traversal method prints the value of the node after visiting its left subtree and before its right subtree?
A. Preorder
B. Inorder
C. Postorder
D. Level-order
Correct Answer:
B
Chapter: 14
Q246:
In a recursive function, what condition signifies the end of recursion?
A. Node is not NULL
B. Node has a right subtree
C. Node is NULL
D. Node has a left subtree
Correct Answer:
C
Chapter: 14
Q247:
What is the primary difference between recursive and non-recursive tree traversal?
A. Recursive uses a queue, non-recursive uses a stack
B. Recursive uses a stack, non-recursive uses a queue
C. Recursive uses function calls, non-recursive uses an explicit stack
D. Recursive uses a stack, non-recursive uses an array
Correct Answer:
C
Chapter: 14
Q248:
What does the inorder function do when it encounters a NULL node?
A. Prints the value of the node
B. Terminates recursion and returns to the previous node
C. Continues traversing the right subtree
D. Pushes the node onto the stack
Correct Answer:
B
Chapter: 14
Q249:
How does the preorder traversal visit the nodes in the binary tree?
A. Node -> Left subtree -> Right subtree
B. Left subtree -> Node -> Right subtree
C. Left subtree -> Right subtree -> Node
D. Node -> Right subtree -> Left subtree
Correct Answer:
A
Chapter: 14
Q250:
What is the output sequence of an inorder traversal on a binary tree?
A. Root node value, followed by left and right subtrees
B. Left subtree values, then root node value, followed by right subtree values
C. Root node value, followed by right subtree and then left subtree
D. Right subtree values, then root node value, followed by left subtree
Correct Answer:
B
Chapter: 14
Q251:
What is the role of the stack in non-recursive tree traversal methods?
A. To store node values for later use
B. To manage function calls and return addresses
C. To keep track of node visitation order
D. To store tree nodes and manage traversal
Correct Answer:
D
Chapter: 14
Q252:
In the inorder traversal non-recursive method, what happens when the pointer p is NULL?
A. The traversal ends immediately
B. The stack is checked for any remaining nodes
C. The pointer p is set to the root node
D. The traversal continues by visiting the right subtree
Correct Answer:
B
Chapter: 15
Q253:
What data structure is most suitable for level-order traversal of a binary tree?
A. Stack
B. Array
C. Queue
D. Linked List
Correct Answer:
C
Chapter: 15
Q254:
In a level-order traversal, which node is processed first?
A. The leftmost node at the deepest level
B. The rightmost node at the deepest level
C. The root node
D. The rightmost node at the top level
Correct Answer:
C
Chapter: 15
Q255:
What is the primary advantage of using a queue for level-order traversal?
A. It supports LIFO operations
B. It supports FIFO operations
C. It simplifies sorting of nodes
D. It provides a way to skip nodes
Correct Answer:
B
Chapter: 15
Q256:
Which traversal method processes nodes level by level from top to bottom?
A. Inorder
B. Preorder
C. Level-order
D. Postorder
Correct Answer:
C
Chapter: 15
Q257:
In the provided levelorder function, what does line 5 check for?
A. Whether the queue is empty
B. Whether the treeNode is NULL
C. Whether the node has a left child
D. Whether the node has a right child
Correct Answer:
B
Chapter: 15
Q258:
What is the purpose of the enqueue method in the levelorder function?
A. To remove nodes from the queue
B. To add nodes to the queue
C. To check if the queue is empty
D. To print the nodes in the queue
Correct Answer:
B
Chapter: 15
Q259:
In a binary search tree (BST) with strings, what function is used to compare two strings?
A. compare()
B. strcmp()
C. compareStrings()
D. compareChar()
Correct Answer:
B
Chapter: 15
Q260:
What happens if strcmp() returns 0 during the insertion of a string into a BST?
A. The string is inserted into the tree
B. A duplicate message is displayed and the new node is deleted
C. The string is ignored and not inserted
D. The insertion process is restarted
Correct Answer:
B