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.
Priority queue operations
Logical service order
Example priority queue loaded. Choose an operation.
Heap array
| Index | Value | Priority | Arrival # | Parent |
|---|
Operation history
- 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
| Relationship | Formula / rule |
|---|---|
| Parent | floor((i − 1) / 2) |
| Left child | 2i + 1 |
| Right child | 2i + 2 |
| Stable comparison | Higher priority first; earlier arrival breaks ties. |