Priority Queue
A priority queue is a special type of queue in which each element
is associated with a priority and is served according to its priority.
If elements with the same priority occur, they are served
according to their order in the queue.Generally, the value of the
element itself is considered for assigning the priority.
For example, The element with the highest value is considered as
the highest priority element. However, in other cases, we can
assume the element with the lowest value as the highest priority
element. In other cases, we can set priorities according to our
needs.
Priority Queue is an extension of queue with following properties.
1. Every item has a priority associated with it.
2. An element with high priority is dequeued before an element with low priority.
3. If two elements have the same priority, they are served according to their order
in the queue.
Basic Operations
insert / enqueue − add an item to the rear of the queue.
remove / dequeue − remove an item from the front of the queue.
Applications of Priority Queue:
1) CPU Scheduling
2) Graph algorithms like Dijkstra’s shortest path algorithm, Prim’s Minimum Spanning Tree,
etc
3) All queue applications where priority is involved.
DEQUE-
A double ended queue also called as deque (pronounced as ‘deck’ or
‘dequeue’) is a list in which the elements can be inserted or deleted at either end in
constant time. It is also known as a head-tail linked list because elements can be
added to or removed from either the front (head) or the back (tail) end. However, no
element can be added and deleted from the middle….
An input-restricted deque is one where deletion can be made from both ends, but
insertion can be made at one end only.
An output-restricted deque is one where insertion can be made at both ends, but
deletion can be made from one end only.