Priority Queue / Heap
Explore the priority queue implemented with heap data structures in Go. Understand how min-heaps and max-heaps function, their applications in extracting min/max values and sorting, and learn essential operations like insert, remove, and heapify with time complexities.
We'll cover the following...
Introduction
Heap is a data structure used to implement the priority queue. In a heap, the data is logically organized as a complete binary tree. A complete binary tree is a binary tree that is filled at all possible levels except the last level. The parent value of each node in a heap is greater (or smaller) than the value of its child nodes.
Types of heaps
There are two types of heap data structures which are briefly described below.
-
Min-heap: Each node’s value should be less than or equal to the values of its children.
-
Max-heap: Each node’s value should be greater than or equal to the values of its children. ...