Data Structures & Algorithms part-7 ( Queue )

Jahangir Alam
4 min readSep 23, 2019

--

A queue is a linear structure which follows a particular order in which the operations are performed. The order is First In First Out.

Implementation Options of Queue

Common operations of Queue

Linear queue (Array implementation)

Creation of Linear Queue ( Array implementation )

Enqueue operation

first insert 10 then 20, then 30 for dequeue operation first dequeue 10 then 20 then 30

Dequeue operation

Peek operation

isEmpty / isFull operation

Time complexity of linear Queue ( Array implementation )

Circular queue

In linear queue when we dequeue value from queue, dequeue value from the start. so at the time of dequeue we can’t use this front space. If we utilize space then we should implement Circular queue.

Circular Queue is a linear data structure in which the operations are performed based on FIFO (First In First Out) principle and the last position is connected back to the first position to make a circle. It is also called ‘Ring Buffer’. In a normal Queue, we can insert elements until queue becomes full.

How Circular Queue works

Enqueue operation of Circular Queue (Array implementation)

Dequeue operation

s/b = start/beginning, t = top

If we are trying to dequeue an element and there is no element in the queue then we simply return error message.

Peek/isEmpty/isFull/Deletion

Time complexity

Linear queue ( Linked list implementation )

creation/enqueue operation

Dequeue operation

In dequeue we have two operation over here.

One if the queue is empty then simply return error message.

then if there is at least one element in the queue then we can perform dequeue successfully .

Peek/isEmpty/Deleting operation

Time complexity

--

--

No responses yet