Heap ordering
Each parent has higher service precedence than its children. Therefore, the highest-priority item is always stored at index 0.
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.
Example priority queue loaded. Choose an operation.
| Index | Value | Priority | Arrival # | Parent |
|---|
Each parent has higher service precedence than its children. Therefore, the highest-priority item is always stored at index 0.
When priorities are equal, the smaller arrival number wins. This preserves first-in, first-out behavior among tied items.
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.
Priority queues are used in CPU scheduling, event simulation, Dijkstra's algorithm, A* search, bandwidth management, and emergency processing.
| Relationship | Formula |
|---|---|
| Parent | floor((i − 1) / 2) |
| Left child | 2i + 1 |
| Right child | 2i + 2 |
| Stable comparison | Higher priority first; earlier arrival breaks ties. |