Priority Queue Simulator

A priority queue removes the most important item rather than the oldest item. This simulator uses a stable binary max heap: larger priority numbers are served first, while items with equal priority preserve FIFO insertion order.

EnqueueO(log n)
DequeueO(log n)
PeekO(1)
Stable tiesFIFO

Priority queue operations

400 ms

Logical service order

Example priority queue loaded. Choose an operation.

Queue size0
Highest priority—
Comparisons0
Swaps0

Heap array

IndexValuePriorityArrival #Parent

Operation history

  1. No operations yet.

Priority queue concepts

Heap ordering

Each parent has higher service precedence than its children. Therefore, the next item to serve is always stored at index 0.

Stable equal priorities

When priorities are equal, the smaller arrival number wins. This preserves first-in, first-out behavior among tied items.

Logical versus physical order

The heap array is not fully sorted. The service-order row uses a sorted copy only to show the order in which items would leave.

Common applications

Priority queues appear in CPU scheduling, event simulation, Dijkstra's algorithm, A* search, bandwidth management, and emergency processing.

Binary heap relationships

RelationshipFormula / rule
Parentfloor((i − 1) / 2)
Left child2i + 1
Right child2i + 2
Stable comparisonHigher priority first; earlier arrival breaks ties.