Heap
Heap
1. Introduction
Heap is a complete binary tree. It is useful for :
(1) Sorting element in the heap (Heap sort, not statble)
(2) Find the top k largest/smallest problem(minHeap stores top k largest, while maxHeap store top k smallest)
2. Construction
(1) MinHeap/ MaxHeap
(2) Self Defined Heap
3. Time & Space Complexity
Insertion: O(logn), where n is the number of elements in the heap
Deletion: O(logn)
GetMIn/GetMax: O(1)
4. Question
Top k largest/smallest: Find Median from Data Stream, Top K Frequent Elements, Sliding Window Maximum
Scan line: The Skyline Problem, Meeting Rooms II
Last updated