In a min-heap, where is the minimum element located?
a) At the root
b) At a leaf node
c) In the middle of the heap
d) At the last position
Answer:
a) At the root
Explanation:
In a min-heap, the minimum element is always located at the root. This is because a min-heap is a binary tree in which each parent node is less than or equal to its child nodes, ensuring that the root contains the smallest value.
When extracting the minimum element, the root is removed, and the heap is restructured (heapified) to maintain the heap property. This allows for efficient access to the minimum element in O(1) time.
Min-heaps are commonly used in priority queues and algorithms like Dijkstra’s shortest path algorithm.
Reference:
DSA (Data Structures and Algorithms) MCQ Questions and Answers