Data Structures MCQs with Answers
Practice important Data Structures MCQs with answers and explanations.
Multiple Choice Questions
Q481: What is the advantage of using a heap over an array for a priority queue?
- A: Heaps provide constant time access to elements
- B: Heaps maintain sorted order
- C: Heaps offer efficient insertion and deletion
- D: Heaps use less memory
View Answer
C
Q482: What is the root node of a min-heap?
- A: The maximum value
- B: The minimum value
- C: The average value
- D: The median value
View Answer
B
Q483: In a min-heap, where is the minimum element located?
- A: At the bottom of the heap
- B: At the root of the heap
- C: At the end of the array
- D: At the middle of the heap
View Answer
B
Q484: What is the time complexity for inserting a single element into a min-heap?
- A: O(1)
- B: O(log N)
- C: O(N)
- D: O(N log N)
View Answer
B
Q485: Which method is used to adjust a min-heap after deleting the root node?
- A: percolateUp
- B: percolateDown
- C: heapify
- D: balance
View Answer
B
Q486: What is the result of calling deleteMin() on a min-heap?
- A: The root node is deleted and replaced by the smallest child
- B: The root node is replaced by the largest child
- C: The entire heap is emptied
- D: The root node is replaced by the maximum child
View Answer
A
Q487: When building a heap from an array of N elements, what is the worst-case time complexity of the buildHeap method?
- A: O(N)
- B: O(N log N)
- C: O(log N)
- D: O(1)
View Answer
A
Q488: How does the percolateDown method work in a min-heap?
- A: Moves a node up to its correct position
- B: Moves a node down to its correct position
- C: Swaps nodes randomly
- D: Resets the heap structure
View Answer
B
Q489: Which of the following operations is necessary to maintain a min-heap property during insertion?
- A: Inserting elements at random places
- B: Moving the element to the bottom
- C: Swapping with parent nodes until heap property is restored
- D: Removing the largest element
View Answer
C
Q490: When an element is inserted into a min-heap, which of the following is true?
- A: It is placed at the root node
- B: It is placed at the bottom of the heap
- C: It is placed at the last position of the array and then moved up
- D: It is placed in the middle of the heap
View Answer
C