What is a queue? What are the applications of queue?

  • A queue is a linear data structure that follows the FIFO (First In First Out) approach for accessing elements.
  • Dequeue from the queue, enqueue element to the queue, get front element of queue, and get rear element of queue are basic operations that can be performed.
    * Some of the applications of queue are:
    1. CPU Task scheduling
    2. BFS algorithm to find shortest distance between two nodes in a graph.
    3. Website request processing
    4. Used as buffers in applications like MP3 media player, CD player, etc.
    5. Managing an Input stream

Queue is used whenever we need to manage any group of objects in an order in which the first one coming in, also gets out first while the others wait for their turn, like in the following scenarios:

  1. In real life scenario, Call Center phone systems uses Queues to hold people calling them in an order, until a service representative is free.
  2. Handling of interrupts in real-time systems. The interrupts are handled in the same order as they arrive i.e First come first served.
  3. Serving requests on a single shared resource, like a printer, CPU task scheduling etc.