What are priority Queues? How can priority queues be implemented? Explain in
brief.
Ans:
Priority Queues:-
There are some queues in which we can insert items or delete items from any
position based on some property. Now, those queues based on the property of
priority of the task to be processed are referred to as priority queues.
To implement a priority queue we first need to identify different levels of priority
and categorize them as the least priority through the most priority level. After
having identified the different levels of priority required, we then need to classify
each incoming item (job) as to what priority level should be assigned to it. While
creating the queues, we need to create n queues if there are n priority levels
defined initially. Let suppose there are three priority levels identified as P1, P2,
and P3. In this case we would create three queues as Q1, Q2 and Q3 each
representing priority levels P1, P2, and P3 respectively. Now every job would have
a priority level assigned to them. Jobs with priority level as P1 will be inserted in
Q1. Jobs with priority level P2 are inserted in Q2 and so on.
No comments:
Post a Comment