Basic Concept of Binary Heap
Prerequisite Knowledge
Before reading this article, you should first learn:
Summary in One Sentence
A binary heap is a data structure capable of dynamically sorting, extending from the binary tree structure.
The main operations of a binary heap are twofold: sink
(downward adjustment) and swim
(upward adjustment), which are used to maintain the properties of the binary heap.
The primary applications of a binary heap are twofold: firstly, as a very useful data structure known as a priority queue, and secondly, as a sorting method called heap sort.
This visualization panel intuitively demonstrates the basic operations of a binary heap. You can click to execute the code within, or modify the code yourself for practice:
Next, I will use the visualization panel to demonstrate the principles of a binary heap. Finally, I will show the implementation of a binary heap using a priority queue as an example.