A Queue is an abstract linear data structure serving as a collection of elements that are inserted (enqueue operation) and removed (dequeue operation) according to the First in First Out (FIFO) approach.
Takeaways
- Queue works on the FIFO principle.
- Queue data structure has appications in various areas such as Operating System, Networks, Multiprogramming etc.
Introduction to Queue
A queue is a linear sequence of items arranged in an ordered fashion. It is based on the FIFO (First In First Out) i.e.i.e. item can only be inserted at the rear end of the queue and removed from the front end of the queue. Most of you will say, it is similar to an array but the catch here is that we can only access the front element of the queue at any given instance of time unlike accessing any arbitrary element in the array. For more details kindly visit our article on Queue in Data Structure.
Application of Queue Data Structure
CPU Job Scheduling, Disk Scheduling
CPU performs huge amounts of jobs continuously, and these jobs should be executed one by one. There are numerous jobs that need to be done by a processor, for example, Keyboard button press, mouse click, opening an application, etc.
These jobs/tasks are brought into the main memory (RAM) and then assigned to the processor one by one in sequential order which is implemented by a Queue.
For example –
- FCFS (First Come First Serve) Scheduling
- Round Robin Scheduling
- Multilevel Queue Scheduling
Multiprogramming
If there are multiple programs in the main memory waiting to get executed, then it is called multiprogramming. The various programs are organized in the form of the queue and the formed queues are known as Ready Queues.
For simultaneous execution of the programs, the processor will execute the programs by accessing them from the cache memory.
For Operation on Data Structures
Earlier we have seen many concepts in the Graph and Tree data structure that requires a queue, for example, Level Order Tree Traversal and Breadth First Search require the queue data structure to process the nodes.
In Operation Systems
- In FCFS (First Come First Serve) scheduling.
- Spooling (sending print requests before the current task is finished) in printers can be achieved using queues.
- It acts as a buffer for certain devices like Keyboard.
- Queues are extensively used in Semaphores.
In Networks
- Packet Queueing.
- Queues in routers/switches
Some Other Common Examples –
- Various Customer care call centers use Queues to hold people calling them and answering their calls in order.
- ‘Queue’ of our favorite music listening application is implemented using the Queue data structure.
- It is very widely used for performing different types of simulations.
- When we submit our code in any programming contest, many of the times we see submission status to be in queue, it is also an implementation queue to execute one’s code who submitted it first.
Conclusion
- Queue is a very important data structure that works on the FIFO (First In First Out) principle.
- There are many applications of queue in data structure like Tree Traversal, Breadth Fist Traversal, etc.
- Queue data structure finds its application in a variety of areas ranging from Operating Systems, Networking, to traversing different data structures.