AlgoMaster Logo

PriorityQueue

High Priority13 min readUpdated June 6, 2026

PriorityQueue is a queue where the smallest element always comes out first, no matter the order you put things in. It's backed by a binary min-heap stored in an array, which gives O(log n) inserts and removals and O(1) access to the head. This lesson covers how the heap is laid out, the API you'll actually use, how to flip it into a max-heap with a Comparator, the gotchas around iteration order and null values, and the kinds of problems it suits well.

Premium Content

Subscribe to unlock full access to this content and more premium articles.