Queue basics and representation

Queue is a data structure used for storing collection of data where order in which data is arriving is important. In Queue, insertion and deletion both happened from the different end.
Data insertion are done at one end which is known as “rear end” while data deletion are done at other end known as “front end“. The data which is arrived first will be deleted first in Queue. This data ordering is called as First in First out or FIFO.

Properties of Queue

  • Insertion and Deletion both happened from the different end.
  • Sequence in which data is arrived is important.
  • Data can be accessed in Queue in FIFO (First in First out) format.

Let’s look into the below diagram to understand how Queue works.

Applications of Queue

  • Operating System Jobs scheduling
  • Asynchronous data transfer such file, sockets etc.
  • FIFO scenario handling such as attending customers
  • Multiprogramming

Queue Operations

  • Enqueue – This operation will add an entry into the Queue at the rear end of the Queue. In case Queue is full then error is returned. This condition is called Queue Overflow.
  • Dequeue – This operation will remove the front entry from the Queue. In case Queue is empty then error is returned. This condition is called Queue Underflow.
  • IsEmpty – This operation will check whether Queue is empty or not.
  • Size/Entries – This operation will return the number of entries present in Queue.
  • AtFront – This operation will return the front element from the Queue. This operation will not remove the front element from the Queue.

Implementation of Queue

  • Simple circular array
  • Dynamic circular array
  • Linked List implementation

Comparison between Simple Array vs Linked List implementation

ParameterSimple ArrayLinked List
Space ComplexityO(n)O(n)
Enqueue() Time ComplexityO(1)O(1)
Dequeue() Time ComplexityO(1)O(1)
IsEmpty() Time ComplexityO(1)O(1)
Entries() Time ComplexityO(1)O(1)
IsFull() Time ComplexityO(1)O(1)
DeleteQueue() Time ComplexityO(1)O(n)
Queue SizeExpensive expansion operation once a whileGraceful expansion or shrink operation
Space and Time UsageNo extra space neededExtra space needed along with reference manipulation

Leave a Reply

Your email address will not be published. Required fields are marked *