A binary heap that always serves the highest-priority element first. Insert sifts up and extract sifts down in O(log n); peek is O(1). Switch between a min-heap and a max-heap.
A binary heap that always serves the highest-priority element first. Insert sifts up and extract sifts down in O(log n); peek is O(1). Switch between a min-heap and a max-heap.
Time complexity: O(log n). Space complexity: O(n).
Use the interactive visualizer above to run Priority Queue (Heap) on your own input and watch every comparison, swap, and operation animate step by step — pause, scrub, or replay at any speed.