Skip to main content

Data Structures MCQs with Answers

Practice important Data Structures MCQs with answers and explanations.

Chapter: 31
Q501:
What is the purpose of the BuildHeap algorithm?
A. To insert elements one by one into the heap
B. To build a heap from an unordered array
C. To sort the array in ascending order
D. To find the maximum element in the heap
Correct Answer: B
Chapter: 31
Q502:
Which method is used to restore the heap order after deleting the root in a min-heap?
A. percolateUp
B. percolateDown
C. insert
D. deleteMin
Correct Answer: B
Chapter: 31
Q503:
In the BuildHeap algorithm, why do we start with i = N/2?
A. To process leaf nodes
B. To process the root node
C. To process internal nodes
D. To start the heap construction from the end
Correct Answer: C
Chapter: 31
Q504:
What does the percolateDown procedure do?
A. Moves larger values up the tree
B. Moves smaller values up the tree
C. Moves smaller values down the tree
D. Moves larger values down the tree
Correct Answer: C
Chapter: 31
Q505:
What does the decreaseKey method do in a heap?
A. Increases the value of the key at position p
B. Decreases the value of the key at position p
C. Removes the node at position p
D. Restores the heap order after insertion
Correct Answer: B
Chapter: 31
Q506:
What is the role of the increaseKey method in a heap?
A. It increases the value of the key at position p
B. It decreases the value of the key at position p
C. It removes the node at position p
D. It restores the heap order after insertion
Correct Answer: A
Chapter: 31
Q507:
How does the remove method work in a heap?
A. It directly removes the node at position p
B. It decreases the value of the node to a very small value and then deletes the root
C. It increases the value of the node to a very high value and then deletes the root
D. It swaps the node with the root and deletes the root
Correct Answer: B
Chapter: 31
Q508:
What is the primary use of the decreaseKey method in a priority queue?
A. To increase the priority of an element
B. To decrease the priority of an element
C. To remove an element from the priority queue
D. To add an element to the priority queue
Correct Answer: B
Chapter: 31
Q509:
In the provided C++ code, what does the insert method do?
A. Inserts an element into the heap while maintaining the heap order
B. Deletes the minimum element from the heap
C. Gets the minimum element from the heap
D. Checks if the heap is full
Correct Answer: A
Chapter: 32
Q510:
What is the purpose of the percolateDown method in a heap?
A. To restore heap order by moving elements down
B. To insert elements into the heap
C. To build the heap from an array
D. To remove the minimum element from the heap
Correct Answer: A
Chapter: 32
Q511:
In the percolateDown method, which condition ensures that the right child is considered if it is smaller than the left child?
A. child != currentSize && array[child+1] < array[child]
B. child < currentSize
C. array[child] < tmp
D. hole * 2 <= currentSize
Correct Answer: A
Chapter: 32
Q512:
What does the getMin method return?
A. The maximum value in the heap
B. The minimum value in the heap without removing it
C. The size of the heap
D. The root element of the heap
Correct Answer: B
Chapter: 32
Q513:
What does the buildHeap method do?
A. It inserts elements into the heap one by one
B. It builds a heap from an unordered array
C. It removes elements from the heap
D. It sorts the elements in the heap
Correct Answer: B
Chapter: 32
Q514:
Which line in the buildHeap method initializes the currentSize variable?
A. for(int i = 1; i <= n; i++)
B. currentSize = n
C. for( int i = currentSize / 2; i > 0; i-- )
D. array[i] = anArray[i-1]
Correct Answer: B
Chapter: 32
Q515:
What is the time complexity of the buildHeap algorithm?
A. O(N log N)
B. O(N)
C. O(log N)
D. O(N^2)
Correct Answer: B
Chapter: 32
Q516:
Why is the percolateDown method preferred over swapping in terms of efficiency?
A. It reduces the number of swap operations needed
B. It increases the number of comparisons made
C. It simplifies the code
D. It increases the number of loop iterations
Correct Answer: A
Chapter: 32
Q517:
In the percolateDown method, what is the purpose of the tmp variable?
A. To store the value at the current index for comparison
B. To store the value of the minimum child
C. To store the value of the root element
D. To store the index of the smallest child
Correct Answer: A
Chapter: 32
Q518:
What does the isEmpty method check in the heap class?
A. If the heap has reached its maximum capacity
B. If the heap has no elements
C. If the heap is full
D. If the heap has space for more elements
Correct Answer: B
Chapter: 32
Q519:
How does the increaseKey method in a heap operate?
A. It increases the value of a key at a specified position
B. It decreases the value of a key at a specified position
C. It removes a key from the heap
D. It restores the heap order after insertion
Correct Answer: A
Chapter: 32
Q520:
What is the significance of the height of a node in a binary tree for the buildHeap process?
A. It determines the number of levels in the heap
B. It affects the efficiency of heap operations
C. It defines the position of the node in the array
D. It influences the time complexity of heap construction
Correct Answer: B

Test Your Knowledge

Take a timed quiz on Data Structures

🚀 Start Quiz Now