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. Operating System, due on Friday Priority Number 4.Data Structures and Algorithms, due on Wednesday Priority Number 2. Statistics, due on Tuesday Priority Number 1.Database Management Systems, due on Thursday Priority Number 3.So instead, you assign a priority to each of them and get them done in that order. Data Structures and Algorithms, due on WednesdayĪs a student, overburdened with work, if you do first come, first serve, you might not be able to submit all your assignments on time.Database Management Systems, due on Thursday.Deletion : O ( l o g n ) O(log n) O ( l o g n )Ĭonsider a situation where you have 4 assignments, as of Monday:.Insertion : O ( l o g n ) O(log n) O ( l o g n ).That is, higher priority elements are served first. And, elements are served on the basis of their priority. A priority queue is a special type of queue in which each element is associated with a priority value.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |