Queues

Niel Kakkad
Strategio
Published in
4 min readOct 31, 2022

In this blog, I’ll be talking about one of the most important data structures One can study, and that’s a Queue. I’m going to talk about a little bit of what I have learned so far and the below is going to be a representation of such!

So what are Queues?

A Queue is a data structure that enables us to create an array of elements and manage its data in First-In-First-Out (FIFO) logic. Queues are typically used to manage threads in multithreading and implementing priority queuing systems. You can reference the image below to get an idea.

Credit: callicoder.com

First In First Out

Just like a Stack, we can easily represent a queue’s functionality with a real-world example. Let’s consider people lined up in a queue to buy a ticket at a movie theatre. A new person will join the line at the end and the person standing in the front will be the first to get the ticket and exit the line. Similarly in a queue data structure, data added first will leave the queue first. When referencing adding an element to the queue we use the term Enqueue and when referencing removing an element we use the term Dequeue. When we enqueue an element we are adding it to the tail(end) of the data structure and when we dequeue an element we are removing it from the head(beginning) of the data structure. Reference the image below!

Credit: geeksforgeeks.org

Types of Queues

There are four different types of queues:

  • Simple Queue
  • Circular Queue
  • Priority Queue
  • Double Ended Queue

Simple Queue

It is the most basic queue in which the insertion of an element is done at the front of the queue and deletion takes place at the end of the queue, its structure is FIFO (First in, First Out).

Credit: programiz.com

To learn more, visit Queue Data Structure.

Circular Queue

A Circular Queue is a linear data structure based on the First In First Out (FIFO) principle, wherein the last element is joined to the first element to create a circle.

Credit: programiz.com

The main advantage of a circular queue over a simple queue is better memory utilization. Also known as a Ring Buffer, Circular Queues were introduced to overcome a queue’s limitation of not being able to utilize the vacant spaces left in the beginning once the rear reaches its end position.

To learn more, visit Circular Queue Data Structure.

Priority Queue

Every now and then we need to process items in a queue in a particular order. A priority queue is a Data Structure that does the job. Java priority queue is different from a “simple” queue. Instead of “First-In-First-Out”, it retrieves the items in the order of their priority.

Credit: programiz.com

To learn more, visit Priority Queue Data Structure.

Deque (Double-Ended Queue)

In a double-ended queue, insertion and deletion can take place at both the front and rear ends of the queue

Credit: programiz.com

To learn more, visit Deque Data Structure.

I’ve written just a fraction about this data structure here today and I’ve barely even scratched the surface so feel free to study these on your own. Google DSA in a language of your choosing or you can check out courses on Udemy, Coursera, or even Youtube. I’m sure I don’t have to tell you how important DSA’s are. I know, I’ve struggled with them as I just started my coding journey about a year ago so I’m sure there are others in the same position as me but never give up even when you feel like throwing away your laptop as I’ve wanted to sometimes. Take a break, do whatever you need to, and come back with a fresh mindset. Practice makes you perfect, and you don’t even need to be perfect but you will be better for it. Thank you, for checking out this week’s blog and if any of this helps or you like what you see please hit the follow button or give it a like!

--

--