In an ascending order priority queue, all the elements are compared with another and the rule: the element that entered the priority queue first will be the first to be removed.Īs mentioned before, the elements in the priority queue must be comparable which means they are either less than, equal to or greater than one another. If two elements in the queue have the same priority value then the first in first out rule is followed for these two elements alone i.e. ![]() Higher or lower priority elements must be dequeued before lower or higher priority elements respectively depending on priority order taken by user that is if user consider lower number as higher priority or higher number as higher priority.Each item in the queue must have a priority associated with it.Characteristics of a Priority QueueĪ queue is called a Priority Queue when it has the following characteristics: (in such a way that the highest priority elements are moved to the beginning of the queue and the lowest priority elements are moved to the back of the queue). ![]() Hence, the items in the priority queue are arranged in either ascending or descending order depending on the priority value taken by the user. However, in a Priority Queue, each item in the queue is assigned a priority, and items are dequeued or removed based on this priority value assigned to them. Just like any queue we form, the person that stands first in the queue, will be addressed first and similarly, even in computer science queues, the same rule applies. In a normal Queue, first-in-first-out is followed which means that whichever elements enters the queue first, will be the first to leave. It is an Abstract Data Type that functions a little differently than a normal Queue. if the two elements are a and b, they should follow one of the conditions:Īs a result, the items in the priority queue are arranged in ascending or descending order. Elements are called comparable if they are either lesser than, equal to or greater than one another, i.e. It is important to note that a priority queue only supports elements that are comparable.
0 Comments
Leave a Reply. |