Fundamentals
What is this?
Before you can use a priority queue, you need the building blocks underneath it. A queue serves people in the order they arrived, a deque lets you add or remove from either end, and a heap always keeps the most important item one step away. This bucket is about learning how these structures actually work, so the later problems feel easy.
💡 Fun fact: A binary heap is stored as a plain flat array with no pointers at all. The "tree" is imaginary, computed from index math, which is why heaps are so fast and cache-friendly.
🔓 Sign in free to read the deep dives. Sign in with Google or Microsoft to start solving.
Core idea: Before you can wield a priority queue, you need the primitives underneath it. A queue gives you fair, in-order processing (FIFO). A deque lets you add and remove from both ends in constant time. A binary heap quietly keeps the smallest (or largest) element one step away at all times. These three structures are the vocabulary that the rest of the chapter speaks in, so this bucket is about mechanics, not problems.
The pattern
These pages are concept primers, not LeetCode walkthroughs. The goal is to internalize how each structure behaves so the later problems feel like applications rather than puzzles.
- Simple Queue — first-in, first-out. Enqueue at the back, dequeue from the front. The mental model behind BFS, scheduling, and buffering.
- Deque — a double-ended queue: push and pop at either end in O(1). The foundation for sliding-window and monotonic-queue tricks.
- Heaps — a binary heap stored as an array, where each parent out-ranks its children. Master
push,pop, andheapify, and you understand every priority queue.
The problems
This bucket holds tutorials rather than problems, so think of each page as a tool you are sharpening.
- Heaps — the star of the chapter. Learn the array layout, the sift-up on insert, the sift-down on removal, and why
heapifybuilds a heap in O(n). Every later "top-K" or "greedy" trick rides on this. - Deque — see why both-ended access matters and where it beats a plain list.
- Simple Queue — the FIFO baseline that grounds the more specialized structures.
Key takeaways
- Queue = FIFO — fairness and order, the basis of BFS and buffering.
- Deque = both ends in O(1) — the workhorse for windows and monotonic patterns.
- Heap = constant-time peek at the extreme — push/pop in O(log n), build in O(n).
- Learn mechanics first — knowing why sift-up and sift-down work makes the problems trivial.
- Why it matters: every priority-queue problem is just one of these structures applied with a clever comparison key.
Order: Simple Queue → Deque → Heaps.