Ds13-Priority Queue
Ds13-Priority Queue
02
Array Implementation of Priority queue
03
03
Applications of Priority Queue
05 AAPP
Applications of Queue
06
05
PRIORITY QUEUE
lower priority.
⚫ Two elements with the same priority are processed on a first-come-
• Prim's Algorithm
• Prim's is another graph algorithm which can utilize a Priority Queue. It works by always selecting the next con
nected edge of lowest path cost.
• CPU Scheduling
• A CPU can only run one process at a time, but there may be many jobs of various priorities waiting to be run.
• A Priority Queue can be used to quickly select the next process to run based upon its priority.
CPU Scheduling
The priority of the process may be set based on the CPU time it requires to get executed
completely. For example, if there are three processes, where the first process needs 5 ns to
complete, the second process needs 4 ns, and the third process needs 7 ns, then the second
process will have the highest priority and will thus be the first to be executed.
However, CPU time is not the only factor that determines the priority, rather it is just one among
several factors. Another factor is the importance of one process over another. In case we have to
run two processes at the same time, where one process is concerned with online order booking
Queues and the second with printing of stock details, then obviously the online booking is more
important and must be executed first.
Multiple Queues
Problems with the queues represented with arrays are:
• We have to allocate large space to avoid the overflow.
• Large space will be wasted due to less size of queue.
There exits a trade-off between the number of overflows and the space.
• One possibility to reduce this tradeoff is to represent more than one
queue in the same array of sufficient size
– Assume that:
• Every minute, 0, 1, or 2 customers will need to be served in a checkout line.
• The expected service time for a customer is 1 minute.
• There is one checkout line available.
– Find the number of customers not served, so far, after n minutes of service.
Probable University Questions
• Explain priority queue.
• List the applications of priority queue.
• Write a C program for Array Implementation of a Priority Queue.
Thank you