Data Structures — Queues

Algorithms and Data Structures From Zero to Hero

Queue in a super-market with anime characters
Image generated using DALL-E

In computer science, a queue is a collection of entities that are maintained in a sequence and can be modified by the addition of entities at one end of the sequence and the removal of entities from the other end of the sequence. The operations of a queue make it a first-in-first-out (FIFO) data structure. — Wikipedia

We define a queue to be a list in which all insertions to the list are made at one end, and all deletions from the list are made at the other end. The element which is first pushed into the order, the operation is first performed on that.

Queue in a super-market with anime characters
Image generated using DALL-E

A queue works exactly as does in real life. Suppose you are in the supermarket and when it is time to pay there is a queue where you have to wait, the first one in is the first one out and the last one in is the last one out (FIFO).

  • Enqueue O(1)
  • Dequeue O(1)

Sequential allocation: You can implement a queue using an array, and it can be organise a limited number of elements.

Linked list allocation: using a linked list, in which it can organise an unlimited number of elements.

  • The queue is called FIFO data structure: First In, First Out.
  • The main operations of a queue are enqueue (addition at the end of the queue) and dequeue (deletion from the front end).

⬅️ Data Structures — Stacks | Table of content | Next (Coming soon) ➡️

--

--

Sometimes I write about technical topics and sometimes about what I feel like.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Kemil Beltre

Sometimes I write about technical topics and sometimes about what I feel like.