What is a Priority Queue?

Data Structure >   Queue Data Structure >   Priority Queue Implementation using Array  

Long Question

1190


Answer:

A Priority Queue is a collection of elements such that each element has been assigned a priority and such that the order in which each elements are deleted and processed comes from the following rules :

  • An element of higher priority is processes before any element of lower priority.
  • Two elements with the same priority are processed according to the order in which they were added to the queue


A priority queue must at least support the following operations:
insert_with_priority: add an element to the queue with an associated priority
pull_highest_priority_element: remove the element from the queue that has the highest priority, and return it.

The algorithm to add an item in the priority queue
This algorithm adds an item with priority number M to a priority Queue maintained by a 2-dimensional array Queue.
1. Insert Item as the rear element in row M of Queue.
2. Exit.

The algorithm to delete an item from a priority queue

This algorithm deleted and processes the first element in a priority queue maintained by a 2-dimensional array Queue
1. [Find the first nonempty queue]
Find the smallest K such that FRONT[K]!=NULL.
2. Delete and process the front element in row K of Queue.
3. Exit.


This Particular section is dedicated to Question & Answer only. If you want learn more about Data Structure. Then you can visit below links to get more depth on this subject.




Join Our telegram group to ask Questions

Click below button to join our groups.