← Back

Priority Queue Simulator

What is a Priority Queue?

A priority queue removes the most important item rather than the oldest item. This simulator uses a stable binary max heap: a larger priority number is 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 highest-priority item 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 is produced from a sorted copy to show the order in which items would leave.

Common applications

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

Binary heap relationships

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