Learn the vocabulary of a complete binary tree that always keeps its smallest or largest element at the root.
0 / 5 completed
1 / 5
At standup, a dev mentions a complete binary tree, stored compactly in an array, where every parent is always smaller (or always larger) than both of its children, letting the smallest (or largest) element always sit at the root. What is this structure called?
A binary heap is exactly this: a complete binary tree, usually stored compactly in a plain array, where the heap property guarantees every parent is always smaller (a min-heap) or always larger (a max-heap) than its children, so the smallest or largest element is always immediately available at the root. A hash collision is an unrelated hash-table concept about two keys sharing a bucket. This root-always-extreme guarantee is exactly why a binary heap is the standard structure behind a priority queue.
2 / 5
During a design review, the team relies on a binary heap's sift-up and sift-down operations to restore the heap property after every insert or removal, rather than fully re-sorting the whole structure each time. Which capability does this provide?
Restoring the heap property with sift-up and sift-down provides logarithmic-time inserts and removals, since each operation only ever needs to adjust elements along a single path from root to leaf, rather than touching every element in the structure. Fully re-sorting the entire structure after every single insert or removal would cost far more, closer to linearithmic time for each individual operation instead of logarithmic. This localized-adjustment behavior is exactly what makes a binary heap efficient enough to back a priority queue under a heavy stream of inserts and removals.
3 / 5
In a code review, a dev notices a scheduler repeatedly re-sorts its entire list of pending tasks from scratch every time a new task arrives, just to find the next task with the earliest deadline. What does this represent?
This is a missed binary heap opportunity, since a heap would keep the task with the earliest deadline sitting right at the root at all times, letting a new arrival be inserted in logarithmic time instead of triggering a full re-sort of every pending task. A cache eviction policy is an unrelated concept about discarded cache entries. This repeated full-sort pattern is exactly the kind of inefficiency a performance-focused reviewer flags, since it redoes far more work than the actual problem, always find the earliest deadline, requires.
4 / 5
An incident report shows a job scheduler's throughput collapsed under load because it re-sorted its entire pending-task list from scratch on every new arrival just to find the task with the earliest deadline, instead of maintaining a structure that kept that task readily available. What practice would prevent this?
Maintaining the pending tasks in a binary heap keyed on deadline keeps the earliest-deadline task always available at the root, and lets each new arrival be inserted in logarithmic time instead of triggering a full re-sort, which is exactly the fix for the throughput collapse described in this incident. Continuing to re-sort the entire list from scratch on every arrival is exactly what caused the collapse as the pending-task list grew under load. This heap-backed priority-queue pattern is the standard fix for any scheduler that repeatedly needs the single most urgent item from a growing, changing set.
5 / 5
During a PR review, a teammate asks why the team reaches for a binary heap instead of just keeping the pending tasks in a fully sorted array, given that both structures let you read the smallest or largest element instantly from one end. What is the reasoning?
A fully sorted array costs linear time to insert a new element in its correct position, since every element after the insertion point has to shift over, while a binary heap's sift-up only ever has to adjust a single path from a leaf back up toward the root, costing logarithmic time instead. Both structures give instant access to the smallest or largest element, but the heap's much cheaper insert is exactly why it's preferred whenever the set of pending items changes frequently. The tradeoff is that a heap doesn't give cheap access to anything other than the single smallest or largest element, unlike a fully sorted array.