Data Structures MCQs with Answers
Practice important Data Structures MCQs with answers and explanations.
Chapter: 11
Q201:
In the C++ implementation of the priority queue, what is the role of the remove() method?
A. Adds an element to the queue
B. Returns and removes the element with highest priority
C. Checks if the queue is empty
D. Sorts the elements in the queue
Correct Answer:
B
Chapter: 11
Q202:
What happens if the remove() method is called on an empty queue?
A. The method returns the last element
B. The method throws an exception
C. The method returns NULL and prints an error message
D. The queue is automatically resized
Correct Answer:
C
Chapter: 11
Q203:
Which method in the PriorityQueue class returns the number of elements currently in the queue?
A. insert()
B. remove()
C. full()
D. length()
Correct Answer:
D
Chapter: 11
Q204:
What does the insert() method in the PriorityQueue class do after adding an element?
A. It sorts the elements in descending order
B. It sorts the elements in ascending order
C. It checks if the queue is full
D. It displays a message if the queue is full
Correct Answer:
B
Chapter: 11
Q205:
In a binary tree, what is a leaf node?
A. A node with two children
B. A node with one child
C. A node with no children
D. A node that is always at the root
Correct Answer:
C
Chapter: 11
Q206:
What is the primary difference between a binary tree and a strictly binary tree?
A. Binary trees do not require nodes to have two children
B. Strictly binary trees require all non-leaf nodes to have two children
C. Binary trees have no defined structure
D. Strictly binary trees can have more than two children per node
Correct Answer:
B
Chapter: 11
Q207:
How is the depth of a binary tree defined?
A. The number of nodes in the tree
B. The level of the root node
C. The maximum level of any leaf node
D. The number of nodes in the longest path
Correct Answer:
C
Chapter: 11
Q208:
In the given C++ PriorityQueue implementation, what is the purpose of the sortElements() method?
A. To remove elements from the queue
B. To check if the queue is full
C. To insert elements into the queue
D. To sort the elements in ascending order
Correct Answer:
D
Chapter: 11
Q209:
What is the characteristic of a non-tree structure shown in the document?
A. It has multiple paths to a node
B. It has only one path to a node
C. It has no nodes
D. It is a linear structure
Correct Answer:
A
Chapter: 11
Q210:
What is the purpose of using a priority queue instead of a regular queue in a simulation?
A. To handle data with varying priorities
B. To handle data with equal priorities
C. To process data in FIFO order
D. To simplify data structure implementation
Correct Answer:
A
Chapter: 12
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
Correct Answer:
B
Chapter: 12
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
Correct Answer:
C
Chapter: 12
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
Correct Answer:
B
Chapter: 12
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()
Correct Answer:
B
Chapter: 12
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
Correct Answer:
B
Chapter: 12
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
Correct Answer:
A
Chapter: 12
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
Correct Answer:
C
Chapter: 12
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
Correct Answer:
C
Chapter: 12
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
Correct Answer:
C
Chapter: 12
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
Correct Answer:
C