Heaps Flashcards
1
Q
What is the difference between a min-heap and a max-heap?
A
Min-Heap: smallest element at root; Max-Heap: largest element at root.
2
Q
What is the time complexity of inserting into a heap?
A
O(log n).
3
Q
What is the time complexity of extracting the min/max from a heap?
A
O(log n).
4
Q
How can you find the k-largest elements in an array?
A
Use Min-Heap of size K.
5
Q
How does a min-heap differ from a max-heap?
A
Min-Heap stores smallest element at root, Max-Heap stores largest.
6
Q
What is the time complexity of sorting a heap?
A
O(n log n).