Playground

Priority Queue

Watch values bubble up and heapify down. Visualize the exact physical memory mapping of a Binary Heap within a flat array.

Priority Queue (Heap)

A Priority Queue is specialized data structure commonly implemented using a Binary Heap (stored internally as a flat array). Elements are ordered such that the root always holds the highest priority element, granting O(log N) insertions and extractions.

Value
HEAP IS EMPTY

INSERT OPERATION

function insert(val):
heap.push(val)
bubbleUp(heap.length - 1)
function bubbleUp(idx):
while idx > 0:
p = (idx - 1) // 2
if heap[p] <= heap[idx]: break
swap(heap[p], heap[idx])
idx = p

Console Output

N=0
>Waiting for operations...