Priority Queue
Always hands back the highest-priority item, usually by keeping a binary heap underneath.
Decision · step 3 of 6Binary Heap: Insert climbs to the root
1 is smaller than its parent 7, so they swap.
What you will see
Items enter at the next free slot and climb; the best one is always the root.
Cost
| insert | O(log n) |
|---|---|
| extract top | O(log n) |
| peek | O(1) |
| Space | O(n) |
Depends on representation; bounds shown are for a binary heap.
How you work with it here
play it through, step one change at a time, scrub to any step, run it on your own input, try operations in any order.
Screen readers: Each element is an accessibility element with position, value and state; structural changes are announced per step.
Reduced motion: Elements appear at their destination with a crossfade; no travel longer than the element's own size.
Before this
Related
Leads to
Topics that need this one first.
Taught by the same lesson
Binary Heap covers these too, in the same run.