23. 合并K个升序链表 https://leetcode.cn/problems/merge-k-sorted-lists
23. Merge k Sorted Lists https://leetcode.com/problems/merge-k-sorted-lists
373. 查找和最小的K对数字 https://leetcode.cn/problems/find-k-pairs-with-smallest-sums
373. Find K Pairs with Smallest Sums https://leetcode.com/problems/find-k-pairs-with-smallest-sums
378. 有序矩阵中第 K 小的元素 https://leetcode.cn/problems/kth-smallest-element-in-a-sorted-matrix
378. Kth Smallest Element in a Sorted Matrix https://leetcode.com/problems/kth-smallest-element-in-a-sorted-matrix
313. 超级丑数 https://leetcode.cn/problems/super-ugly-number
313. Super Ugly Number https://leetcode.com/problems/super-ugly-number
355. 设计推特 https://leetcode.cn/problems/design-twitter
355. Design Twitter https://leetcode.com/problems/design-twitter
215. 数组中的第K个最大元素 https://leetcode.cn/problems/kth-largest-element-in-an-array
215. Kth Largest Element in an Array https://leetcode.com/problems/kth-largest-element-in-an-array
451. 根据字符出现频率排序 https://leetcode.cn/problems/sort-characters-by-frequency
451. Sort Characters By Frequency https://leetcode.com/problems/sort-characters-by-frequency
703. 数据流中的第 K 大元素 https://leetcode.cn/problems/kth-largest-element-in-a-stream
703. Kth Largest Element in a Stream https://leetcode.com/problems/kth-largest-element-in-a-stream
347. 前 K 个高频元素 https://leetcode.cn/problems/top-k-frequent-elements
347. Top K Frequent Elements https://leetcode.com/problems/top-k-frequent-elements
692. 前K个高频单词 https://leetcode.cn/problems/top-k-frequent-words
692. Top K Frequent Words https://leetcode.com/problems/top-k-frequent-words
1845. 座位预约管理系统 https://leetcode.cn/problems/seat-reservation-manager
1845. Seat Reservation Manager https://leetcode.com/problems/seat-reservation-manager
295. 数据流的中位数 https://leetcode.cn/problems/find-median-from-data-stream
295. Find Median from Data Stream https://leetcode.com/problems/find-median-from-data-stream
870. 优势洗牌 https://leetcode.cn/problems/advantage-shuffle
870. Advantage Shuffle https://leetcode.com/problems/advantage-shuffle
1834. 单线程 CPU https://leetcode.cn/problems/single-threaded-cpu
1834. Single-Threaded CPU https://leetcode.com/problems/single-threaded-cpu
Prerequisites
Before reading this article, you need to learn:
The main application of a binary heap is a priority queue, which is characterized by dynamic sorting. Elements inserted can automatically maintain the correct order. Of course, a binary search tree can also achieve dynamic sorting, but the priority queue provides a simpler interface and is easier to implement.
Generally, problems that use priority queues can be divided into two categories. One category involves merging multiple sorted sequences into one, and the other involves finding the k
-th largest element in multiple sorted sequences. Let's look at each category separately.
First, let's look at the first category, which includes problems similar to merging sorted linked lists.