Priority Queue

  • A generalization of Queues
  • All elements inserted have some priority
  • Elements with the highest or lowest priority are removed first
  • Implemented using Binary Heap

Operations

  • Insertion
  • Peek
  • ExtractMin or ExtractMax

Implementations

StructureInsertExtractPeek
Unsorted Array/ListO(1)O(n)O(n)
Sorted Array/ListO(n)O(1)O(1)
Balanced treesO(log n)O(log n)O(log n)
Binary HeapO(log n)O(log n)O(1)

Applications