Queue Data Structure

  • Last Updated : 29 Nov, 2022

Data Structure and Algorithms Course
Practice Problems on Queue
Recent articles on Queue

What is Queue?

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.

What is Queue in Data Structure and Algorithms

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 of queue

FIFO property of 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 :

  1. Introduction to Queue in Data Structures and Algorithms
  2. Implementations of Queue Data Structure
  3. Applications, Advantages and Disadvantages of Queue
  4. Priority Queue
  5. Applications of Priority Queue
  6. Deque
  7. Circular Queue
  8. Queue Interface In Java
  9. Queue In Python
  10. Queue In C#


Implementation :

  1. Implement Queue using Stacks
  2. LRU Cache Implementation
  3. Implement Stack using Queues
  4. Queue | Set 2 (Linked List Implementation)
  5. How to efficiently implement k Queues in a single array?
  6. Implement a stack using single queue
  7. Implementation of Deque using circular array
  8. Circular Queue | Set 2 (Circular Linked List Implementation)
  9. Implement Stack and Queue using Deque
  10. Priority Queue using Linked List
  11. Priority Queue using doubly linked list
  12. Implementation of Deque using doubly linked list

Standard Problems :

  1. Check if a queue can be sorted into another queue using a stack
  2. Breadth First Traversal or BFS for a Graph
  3. Level Order Tree Traversal
  4. Reverse a path in BST using queue
  5. Construct Complete Binary Tree from its Linked List Representation
  6. Program for Page Replacement Algorithms | Set 2 (FIFO)
  7. Check whether a given Binary Tree is Complete or not | Set 1 (Iterative Solution)
  8. Number of siblings of a given Node in n-ary Tree
  9. ZigZag Tree Traversal
  10. FIFO (First-In-First-Out) approach in Programming
  11. FIFO vs LIFO approach in Programming
  12. LIFO (Last-In-First-Out) approach in Programming

Operations on Queue :

  1. Reversing a Queue
  2. Reversing a queue using recursion
  3. Reversing the first K elements of a Queue
  4. Interleave the first half of the queue with second half
  5. Sorting a Queue without extra space

Misc :

  1. Level order traversal in spiral form
  2. Sliding Window Maximum (Maximum of all subarrays of size k)
  3. Find the largest multiple of 3 | Set 1 (Using Queue)
  4. Find the first circular tour that visits all petrol pumps
  5. Smallest multiple of a given number made of digits 0 and 9 only
  6. Iterative Method to find Height of Binary Tree
  7. Implement PriorityQueue through Comparator in Java
  8. An Interesting Method to Generate Binary Numbers from 1 to n
  9. Minimum time required to rot all oranges
  10. Find maximum level sum in Binary Tree
  11. Sum of minimum and maximum elements of all subarrays of size k.
  12. Distance of nearest cell having 1 in a binary matrix
  13. Level order traversal line by line | Set 2 (Using Two Queues)
  14. First negative integer in every window of size k
  15. Minimum sum of squares of character counts in a given string after removing k characters
  16. Queue based approach for first non-repeating character in a stream
  17. Averages of Levels in Binary Tree
  18. Stack Permutations (Check if an array is stack permutation of other)
  19. Check if all levels of two trees are anagrams or not
  20. Check mirror in n-ary tree
  21. Check if X can give change to every person in the Queue

Quick Links :

GeeksforGeeks Courses:

Complete Interview Preparation

Prepare for a job interview with confidence and clarity, Here you’ll get prepared for each and every subject & skill relevant to the interview whether it be core CS subjects, programming language, reasoning & aptitude, resume building, etc. at budget-friendly prices with GeeksforGeeks Complete Interview Preparation Course.

Live Courses

Enrol today to learn data structures, Get best-in-industry real-time GFG Live Courses to upskill yourself and get into your dream company. You can attend these live classes from any geographical region and here you can ask your doubts to the instructor just like an offline classroom program. Do check out these valuable Live Courses by GeeksforGeeks – System Design Live, Competitive Programming Live, and more!

Language Foundation Courses[C Programming / C++ / JAVA / Python ]

Each language is designed to get you right into hands-on practice by offering Language Foundation Courses. Learn any programming language from scratch and understand all its fundamental concepts for a strong programming foundation in the easiest possible manner at best price possible with help of GeeksforGeeks Language Foundation Courses – C Programming | Java Foundation | Python Foundation | C++ Foundation.


My Personal Notes arrow_drop_up