Area Priority Queue
Queue
-----------------------------------------------------------------------------------
---------------------------
--------------------------------------------------------------
Definition A priority queue is a queue in which each element
has a priority. A queue uses FIFO (First-In-First-Out) to remove
elements.
Elements are removed based on their priorities.
Types Min Priority Queue and Max Priority Queue.
It has no specific types.
Structure Each element in the priority queue has a priority.
Queue elements have no priority.
deQueue operation Elements are removed based on their highest
priority. Elements are removed in FIFO order.
Element ordering Ordered queue — elements are sorted by priority.
Random order — processed by arrival time.
Complexity More complex to implement due to element ordering.
Simple and easy to implement.
Syntax PriorityQueue<DataType> queue = new
PriorityQueue<>(); Queue<DataType> queue = new
LinkedList<>();
Properties Inherits methods from AbstractCollection,
AbstractQueue, Uses Queue interface and java.util package.
Object, and Collection.
Operation Insertion and removal (enQueue/deQueue) are more
complex. Insertion and removal are simple and fast.
Advantage Easy to remove the highest-priority element.
Efficient memory usage.
Disadvantage Takes more time to insert and delete elements.
Not ordered and limited for priority-based processing.
deQueue and enQueue time O(log n)
O(1)