Back to Academy
stacks queues
Priority Queue
A Priority Queue is an abstract data structure where each element has a priority, and the element with the highest (or lowest) priority is served first. It is typically implemented using a binary heap, providing efficient insertion and extraction of the minimum or maximum element. It is essential for algorithms like Dijkstra's and Huffman coding.
Use Cases
- •Task scheduling based on priority levels
- •Dijkstra's and Prim's graph algorithms
- •Event-driven simulations and real-time systems
Complexity Analysis
| Metric | Best | Average | Worst |
|---|---|---|---|
| Time | O(1) | O(log n) | O(log n) |
| Space | O(n) | ||
Visualization
35
10
25
5
20
15
30
Implementation
Output
Click "Run Code" to see output...