Queue

Sathya Narayana
4 min readMay 2, 2022

--

In the programming world, Queue is an Abstract Data Type (ADT) that works on the principle of FIFO (First In First Out). It means any data which goes inside the queue, will be getting out of the queue in the same order as they inserted into the queue. See the below animation :

So by this example, we understood what is queue and how it works.

Now let’s understand what a fixed-size queue is and why we need it.

Fixed Size/Capacity Queue

Basically, its name itself gives the answer. It is a queue, and the size of the queue is fixed, which means that the queue cannot hold more than the specified limit of a number of data. In the previous picture, the size of the queue is 5 because it is holding 5 integers.

Basic operations of a queue

  • Enqueue ( ) : Adding items to a queue.
  • Dequeue( ): Using the first item and removing it from the queue.
  • Peek ( ): retrieving the first item from the queue
  • isEmpty ( ) : If queue is empty it return True else False
  • isTrue ( ) : if queue is full it return True else False
  • Delete ( ): Deleting all the items from the queue

Why We Need It

In a normal queue or we can say a dynamic queue where its capacity is not pre-defined or fixed, there are many challenges with it. Because the queue is implemented with the help of an array, it requires contiguous space in the memory. and suppose a situation arises when we want to insert data in the queue but there is no space in the next memory block of the memory, so here is what happens all current data of the array is transferred to a new memory address where contiguous memory space is available and this process is not efficient in terms of resources because its time complexity would be O(n) for each data insertion, that is a huge loss of CPU. So to save our CPU time we pre-plan the size of the array so that the above problem does not appear because by defining the size of the array we reserve the space for the array and no other program can use that space. This is in the implementation of the queue we define the size of the array(size of the queue).

Important use cases of Queue

Use Cases :

In real life there are many use cases of the queue, some of them are listed below :

  • In CPU processing, it processes every process is in a sequence and that sequence is FIFO. It means that the CPU processes those processes first which came first and those last which came last.
  • FIFOs/Queues are commonly used in electronic circuits for buffering and flow control between hardware and software.
  • Queues are used on networks for arranging the data flow of data packets.
  • Other than these there are many use cases for Queues.

Differences between a fixed capacity queue and no fixed limit queue

Implementation of Queue with AI

So basically queue is implemented using arrays, so where is Artificial Intelligence in it. let's understand it.

AI is one of the most emerging fields of computer science and technology, today almost every company uses AI for building/getting suggestions/understanding/ products and customer requirements. And AI can also help in implementing queues, How?

As we saw the benefits of a fixed capacity queue, so defining the size of the queue is one of the major tasks in implementing a queue. And here AI plays an important role.

With the help of AI we can understand the current requirement of the system and according we can set the size of the queue. We can also change the size of the queue with AI when the requirement increases/decreases.

This is part one of Fixed Queue. Let us discuss Some more features and examples next time.

--

--