What is a Priority Queue? How is it Different from an ordinary Queue? Is Heap a Priority Queue? Explain your answers in own words.
Priority Queue: It is a special kind of queue in which each elements are associated with the priority and it is also served as per it's priority.
Priority queue is different ordinary queue because it do not have any end, in ordinary queue , elements are inserted from one end and remove from the other ends but in the priority queue insertion of elements can be in any order but the removal of the elements can be done in sorted order.
So we can conclude that sorting will be done when elements are removed from the priority queue. the priority queue can be easily implemented by a heap.
Heap is a kind of maximally efficient implementation of abstract data type which is also called the priority queue. Generally we say that priority queue is a kind of heap.
Comments
Leave a comment