What is a priority queue?

If we are able to insert and remove the element inside a queue at any position based on some specific or predefine priority then this type of queue is known as a priority queue.

You can understand this with an example given in below Fig1 of a printer and few jobs where jobs are waiting to use the printer to complete their print job on a LAN system.

We have declared few priorities say 1, 2, 3, 4 which is attached to jobs of a supervisor, teacher, students, and out-side users respectively. Now if a job is started with a priority p then it is immediately inserted with at the end of thee of other jobs with priority p. And for p = 1, 2, 3, 4 jobs are always removed front the front place fo the queue.

Fig1: Priority Queue

In a generalized language, we can conclude that a priority queue is the series of the queue where we already know the priority of each element associated with the queue. Fig 1.1 below shows the representation of a single priority queue into four separate queues, each of them following a FIFO technique.

Queue based on priority

When the first queue will be empty then only the element of the second queue will be removed. In the same manner, the element of the third queue will be removed only when the first and second queue will be empty and so on.

This representation of a single priority queue into a series of queues also suggests an efficient storage scenario of a priority queue. on the basis of priority, the element is always added at the end of the queue when they are supposed to add.

If an only a single sequential structure is used for the priority queue then at the time of insertion a new element must be inserted at the middle of the queue. This can require the movement of several elements. Thus it is a better option to split the priority queue into several queues. in which each one will be having its own storage structure.


In general, a queue is known to store the element in a series and is inserted at one end removed from another end. If we can make this insertion and deletion of the element on the basis of prior priority of each element then this type of queue is known as a priority queue.

In the case of any queries, you can write to us at we will get back to you ASAP.

Hope! you would have enjoyed this post about priority queue in data structure.

Please feel free to give your important feedbacks in the comment section below.

Have a great time! Sayonara!