Queue Data Structure

Last Updated : 15 Feb, 2023

Learn more about Queue in DSA Self Paced Course
Practice Problems on Queue
Recent articles on Queue

What is Queue Data Structure?

A Queue is defined as a linear data structure that is open at both ends and the operations are performed in First In First Out (FIFO) order.

We define a queue to be a list in which all additions 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 Data Structure

Queue Data Structure

FIFO Principle of Queue:

  • A Queue is like a line waiting to purchase tickets, where the first person in line is the first person served. (i.e. First come first serve).
  • Position of the entry in a queue ready to be served, that is, the first entry that will be removed from the queue, is called the front of the queue(sometimes, head of the queue), similarly, the position of the last entry in the queue, that is, the one most recently added, is called the rear (or the tail) of the queue. See the below figure.
Fifo Property in Queue

Fifo Property in Queue

Characteristics of Queue:

  • Queue can handle multiple data.
  • We can access both ends.
  • They are fast and flexible. 

Queue Representation:

Like stacks, Queues can also be represented in an array: In this representation, the Queue is implemented using the array. Variables used in this case are

  • Queue: the name of the array storing queue elements.
  • Front: the index where the first element is stored in the array representing the queue.
  • Rear: the index where the last element is stored in an array representing the queue.

Topics :

 


Introduction to Queue Data Structure:

  1. Introduction to Queue – Data Structure and Algorithm Tutorials
  2. Implementations of Queue Data Structure using Arrays
  3. Implementations of Queue Data Structure using Linked List
  4. Applications, Advantages and Disadvantages of Queue
  5. Different Types of Queue


Implementation of Queue in various Programming Languages:

  1. Queue in C++ Standard Template Library (STL)
  2. Queue Interface In Java
  3. Queue In Python
  4. Queue In C#
  5. Queue in Javascript
  6. Queue in Go Language
  7. Queue in Scala


Some other Implementations of Queue Data Structure:

  1. Implementation of Deque using doubly linked list
  2. Implement a stack using single queue
  3. Implement Queue using Stacks
  4. How to efficiently implement k Queues in a single array?
  5. LRU Cache Implementation


Some Must Solve Standard Problems on Queue Data Structure:


Quick Links:

Recomended:


My Personal Notes arrow_drop_up

Share your thoughts in the comments

Similar Reads

Complete Guide to Linked List Data Structure
In this complete guide to Linked List Data Structures, you will learn about the basics of Linked List, how to get started with Linked List, learning, strategy, resources, problems, and much more.
4 min read
Complete Guide to Arrays Data Structure
In this complete guide to Array Data Structures, you will learn about the basics of Arrays, how to get started with Array, learning, strategy, resources, problems, and much more.
4 min read
Complete Guide to String Data Structure
In this complete guide to String Data Structures, you will learn about the basics of string, how to get started with String, learning, strategy, resources, problems, and much more.
4 min read
Data Processing Agreement
Welcome to GeeksforGeeks. This Agreement is between Sanchhaya Education Pvt. Ltd., registered and headquartered at A-143, Sovereign Corporate Towers, 9th Floor, Sector-136, NOIDA, Gautam Buddha Nagar, Uttar Pradesh,201305, hereinafter referred to as ‘Company’ or GeeksforGeeks (“us”, “we”, or “our”) operates https://www.geeksforgeeks.org/ (hereinaft
11 min read
Pandas for Data Visualization: A Complete Guide
Learn Pandas for data visualization, with basic to advanced techniques of plotting and customizing interactive data visualizations.Build interactive charts, graphs, and plots to summarize data and make intuitive reports. This tutorial will help you master data visualization techniques using Pandas and enable you to share your insights graphically.
4 min read
Should we declare as Queue or Priority Queue while using Priority Queue in Java?
Queue: Queue is an Interface that extends the collection Interface in Java and this interface belongs to java.util package. A queue is a type of data structure that follows the FIFO (first-in-first-out ) order. The queue contains ordered elements where insertion and deletion of elements are done at different ends. Priority Queue and Linked List are
3 min read
Static Data Structure vs Dynamic Data Structure
Data structure is a way of storing and organizing data efficiently such that the required operations on them can be performed be efficient with respect to time as well as memory. Simply, Data Structure are used to reduce complexity (mostly the time complexity) of the code. Data structures can be two types : 1. Static Data Structure 2. Dynamic Data
4 min read
Applications of Queue Data Structure
Introduction : A queue is a linear data structure that follows the "first-in, first-out" (FIFO) principle. It is a collection of elements that supports two primary operations - enqueue and dequeue. In the enqueue operation, an element is added to the back of the queue, while in the dequeue operation, an element is removed from the front of the queu
5 min read
Top | MCQs on Queue Data Structure with Answers | Question 25
Consider the below program, and identify what the function is doing. C/C++ Code void function(Node* root) { if (root == NULL) return; queue q; q.push(root); while (q.empty() == false) { Node* node = q.front(); cout data left != NULL) q.push(node->left); if (node->right != NULL) q.push(node->right); } } (A) In order traversal of a tree (B) Normal tr
1 min read
Basic Operations for Queue in Data Structure
Basic Operations on Queue: Some of the basic operations for Queue in Data Structure are: enqueue() - Insertion of elements to the queue.dequeue() - Removal of elements from the queue.peek() or front()- Acquires the data element available at the front node of the queue without deleting it.rear() - This operation returns the element at the rear end w
11 min read