What is a Priority Queue?

Fill In The Blank
Views 1165

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.

Related Articles:

This section is dedicated exclusively to Questions & Answers. For an in-depth exploration of Data Structure, click the links and dive deeper into this subject.

Join Our telegram group to ask Questions

Click below button to join our groups.