Understanding Data Structures: Queues

Understanding Data Structures: Queues

A queue is a linear data structure with its nodes arranged sequentially. Its modification works with the FIFO (First In First Out) principle where the first node in is always the first one out.

It is the direct opposite of the Stack data structure.

Uses Of Queues

  • They Play A Huge Role In Asynchronous computer operations

  • They are used to implement algorithms such as Breadth-First Search

  • They are used in instances like CPU Scheduling

  • Queues such as concurrent queues are used for multi-threading in applications

  • Queues are used to manage task/job flow in a system.

  • Queues are used to manage traffic and requests on a network

Uses of Queues

Linear Queues

A linear queue also known as the simple queue is a type of queue that has its nodes arranged sequentially.

Variants of the Linear Queue:

Implementation Of The Linear Queue:

We first create a class for the Queue, this class would have a property named collection; this property would be used to store all the nodes that would be passed into the queue.

class Queue:
   def __init__(self):
     self.collection= []

Secondly, we start adding methods to the Queue class. These methods are what make the Queue class functional. The first method we would be adding is the Enqueue method.

This method appends nodes to the queue collection😄

def enqueue(self,value):
      self.queue.append(value)

The second method is the Dequeue method, it does the direct opposite of the previous method. It removes the oldest node in the collection, hereby obeying the FIFO(First In, First Out) principle.

  def dequeue(self):
      self.queue.pop(0)
  • Priority Queues

    Priority queues are quite commonly used in the world of computers. It is a queue where nodes are removed based on the order of priority of the queue.

    Every node in a Priority queue has a Priority value attached to itself.

  • Circular Queues

    Circular Queue | Set 1 (Introduction and Array Implementation ...

    Circular Queues are just a variation of normal queues where the last element of the queue is connected to the first.

    In this particular queue, there's a storage limit placed on every instance of this queue and once it is filled no other node can be added to the queue.

    Features of A Circular Queue:

  • It operates on the FIFO principle.

  • It doesn't accept more nodes after being full

  • The first node connects to the last.

P.S: The writeups following the Deque, Priority Queue and Circular Queue in this article was just a preamble. I'll be delving more indepthly into these data structures in my Advanced Data Structures Course.

Thanks for reading, I'll see you on the next one😁