Data Structures MCQs with Answers
Practice important Data Structures MCQs with answers and explanations.
Chapter: 29
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
Correct Answer:
C
Chapter: 30
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
Correct Answer:
B
Chapter: 30
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
Correct Answer:
B
Chapter: 30
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)
Correct Answer:
B
Chapter: 30
Q485:
Which method is used to adjust a min-heap after deleting the root node?
A. percolateUp
B. percolateDown
C. heapify
D. balance
Correct Answer:
B
Chapter: 30
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
Correct Answer:
A
Chapter: 30
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)
Correct Answer:
A
Chapter: 30
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
Correct Answer:
B
Chapter: 30
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
Correct Answer:
C
Chapter: 30
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
Correct Answer:
C
Chapter: 30
Q491:
In a min-heap, what is the maximum number of levels the tree can have if it contains N nodes?
A. log2(N)
B. N
C. sqrt(N)
D. N log2(N)
Correct Answer:
A
Chapter: 30
Q492:
What does a complete binary tree ensure when implementing a heap?
A. All nodes have two children
B. All nodes are in a specific order
C. The tree is balanced
D. All levels are fully filled except possibly the last
Correct Answer:
C
Chapter: 30
Q493:
When performing a percolateDown operation, which of the following is true?
A. The hole moves upward
B. The hole moves downward
C. The node moves to the left
D. The node moves to the right
Correct Answer:
B
Chapter: 30
Q494:
In the heap sort algorithm, how is the smallest element retrieved from the heap?
A. By removing the root node
B. By scanning the entire heap
C. By using a heapify function
D. By moving the last node to the root
Correct Answer:
A
Chapter: 30
Q495:
What is the primary use of the heap data structure?
A. Binary search
B. Priority queues
C. Sorting
D. Hashing
Correct Answer:
B
Chapter: 30
Q496:
How are elements arranged in a min-heap relative to each other?
A. In ascending order from root to leaves
B. In descending order from root to leaves
C. Random order
D. In ascending order from leaves to root
Correct Answer:
A
Chapter: 30
Q497:
How is the complexity of building a heap with the buildHeap method compared to inserting elements one by one?
A. It is faster
B. It is slower
C. It is the same
D. It is unpredictable
Correct Answer:
A
Chapter: 30
Q498:
What happens if you insert an element that is larger than all existing elements in a min-heap?
A. It moves to the root node
B. It stays at the last position
C. It moves to the bottom of the heap
D. It gets discarded
Correct Answer:
B
Chapter: 30
Q499:
When deleting an element from a min-heap, what happens to the heap size?
A. It increases by one
B. It decreases by one
C. It stays the same
D. It doubles
Correct Answer:
B
Chapter: 31
Q500:
What is the time complexity of the insert method for building a heap one element at a time?
A. O(N)
B. O(log N)
C. O(N log N)
D. O(N^2)
Correct Answer:
C