Skip to main content

Data Structures MCQs with Answers

Practice important Data Structures MCQs with answers and explanations.

Chapter: 18
Q321:
What does the serviceCustomer function do with the pointer retrieved from the queue?
A. Prints the customer's name and deallocates the memory
B. Prints the customer's name and keeps the memory allocated
C. Deletes the queue and deallocates all pointers
D. Allocates new memory for the customer
Correct Answer: A
Chapter: 18
Q322:
Why are pointers created inside the loadCustomer function still valid after the function returns?
A. Because they are stored in the queue which is still valid
B. Because they are global pointers
C. Because the objects they point to are on the stack
D. Because the pointers themselves are not destroyed
Correct Answer: A
Chapter: 18
Q323:
How does dynamic memory allocation help when dealing with large objects or arrays?
A. By creating objects on the stack
B. By creating objects on the heap
C. By creating temporary objects
D. By creating references to large objects
Correct Answer: B
Chapter: 18
Q324:
What is a dangling pointer?
A. A pointer that points to an invalid memory location
B. A pointer that points to a valid object
C. A pointer that is not initialized
D. A pointer that points to a new object
Correct Answer: A
Chapter: 18
Q325:
What is the primary difference between stack memory and heap memory in terms of growth direction?
A. Stack grows upward, heap grows downward
B. Stack and heap both grow upward
C. Stack grows downward, heap grows upward
D. Stack grows upward, heap grows downward
Correct Answer: C
Chapter: 18
Q326:
What is the impact of an endless recursive call on the stack memory?
A. It causes stack overflow
B. It increases heap size
C. It reduces heap size
D. It causes heap overflow
Correct Answer: A
Chapter: 18
Q327:
Why are references often used as function parameters with const keyword?
A. To ensure the parameter is not modified and avoid copying
B. To allow the function to modify the parameter
C. To pass the parameter by value
D. To create a new instance of the parameter
Correct Answer: A
Chapter: 19
Q328:
What does the const keyword in C++ do when used with a reference parameter?
A. Prevents the function from modifying the parameter
B. Allows the function to modify the parameter
C. Forces the function to create a copy of the parameter
D. Enables modification of the reference object
Correct Answer: A
Chapter: 19
Q329:
When is it appropriate to use a const keyword at the end of a member function signature?
A. To allow the function to modify member variables
B. To ensure the function does not modify member variables
C. To prevent the function from being called
D. To make the function private
Correct Answer: B
Chapter: 19
Q330:
What is the key feature of an AVL tree compared to a regular binary search tree?
A. It allows any height difference between left and right subtrees
B. It keeps the height difference between left and right subtrees within 1
C. It maintains a complete binary tree structure
D. It uses only one child for each node
Correct Answer: B
Chapter: 19
Q331:
What is the height of a subtree in an AVL tree defined as?
A. The number of nodes in the subtree
B. The maximum depth from the root to any leaf
C. The number of edges from the root to the leaf
D. The sum of the heights of left and right subtrees
Correct Answer: B
Chapter: 19
Q332:
What does the const keyword at the beginning of the return type indicate?
A. The function returns a constant value
B. The function returns a constant reference
C. The function returns a reference that cannot be modified
D. The function returns a constant pointer
Correct Answer: C
Chapter: 19
Q333:
How does a degenerate binary search tree differ from a balanced binary search tree?
A. It is perfectly balanced
B. It has a height equal to the number of nodes
C. It has no left child for any node
D. It has nodes only on one side
Correct Answer: B
Chapter: 19
Q334:
In a degenerate binary search tree, what happens when searching for a value?
A. It is faster than in a balanced tree
B. It involves traversing all nodes sequentially
C. It uses a binary search algorithm efficiently
D. It performs the search in constant time
Correct Answer: B
Chapter: 19
Q335:
What is a key characteristic of an AVL tree?
A. It has nodes with a balance factor of 0 only
B. It maintains a balance factor between -1 and 1
C. It does not require balancing
D. It is always a complete binary tree
Correct Answer: B
Chapter: 19
Q336:
What is the balance factor of a node in an AVL tree?
A. Height of the node
B. Difference in heights between left and right subtrees
C. Number of children
D. Sum of the heights of the left and right subtrees
Correct Answer: B
Chapter: 19
Q337:
What happens if an AVL tree becomes unbalanced during insertion or deletion?
A. The tree remains unbalanced
B. The tree is automatically balanced
C. The tree is converted into a linked list
D. The tree structure is fixed
Correct Answer: B
Chapter: 19
Q338:
What is the purpose of using a const reference in a function return type?
A. To allow the function to modify the returned object
B. To prevent modification of the returned object
C. To ensure the function returns a copy
D. To ensure the returned reference is modifiable
Correct Answer: B
Chapter: 19
Q339:
Which of the following is a correct characteristic of a degenerate binary search tree?
A. It has all nodes with both left and right children
B. It looks like a linked list
C. It is balanced with left and right subtrees
D. It has nodes with varying heights
Correct Answer: B
Chapter: 19
Q340:
In an AVL tree, if the height difference between left and right subtrees of a node is 2, what is the implication?
A. The tree is balanced
B. The node needs to be removed
C. The tree is unbalanced and needs rotation
D. The tree structure is complete
Correct Answer: C

Test Your Knowledge

Take a timed quiz on Data Structures

🚀 Start Quiz Now