Queue Data Structure
Last Updated :
20 Jun, 2025
Improve
A Queue Data Structure is a fundamental concept in computer science used for storing and managing data in a specific order.
- It follows the principle of "First in, First out" (FIFO), where the first element added to the queue is the first one to be removed.
- It is used as a buffer in computer systems where we have speed mismatch between two devices that communicate with each other. For example, CPU and keyboard and two devices in a network
- Queue is also used in Operating System algorithms like CPU Scheduling and Memory Management, and many standard algorithms like Breadth First Search of Graph, Level Order Traversal of a Tree.
Basics

Implementations in various Programming Languages
- Queue in C++ STL
- Queue In Java
- Queue In Python
- Queue In C#
- Queue in JavaScript
- Queue in Go Language
- Queue in Scala
Implementing Other Data Structures Using Queue
Easy Problems on Queue
- Implement Stack using Queues
- Minimum Depth of a Binary Tree
- BFS for a Graph
- Detect cycle in an undirected graph using BFS
- Right View of a Binary Tree
- Check whether a graph is Bipartite
Medium Problems on Queue
- Implement k Queues in a single array
- Flatten a multilevel linked list
- Level with maximum number of nodes
- Find if there is a path between two vertices in a directed graph
- Print all nodes between two given levels in Binary Tree
- Find next right node of a given key
- Minimum steps to reach target by a Knight
- Islands in a graph using BFS
- Find the first non-repeating in a stream
Hard Problems on Queue
- Sliding Window Maximum (Maximum of all subarrays of size K)
- Flood Fill Algorithm
- Minimum time required to rot all oranges
- Shortest path in a Binary Maze
- An Interesting Method to Generate Binary Numbers from 1 to n
- Maximum cost path from source node to destination
- Shortest distance between two cells in a matrix or grid
- Snake and Ladder Problem
- Find shortest safe route in a path with landmines
- Count all possible walks from a source to a destination with exactly K edges
- Minimum Cost of Simple Path between two nodes in a directed and weighted graph
- Minimum Cost Path in a directed graph via given set of intermediate nodes
- Find the first circular tour that visits all petrol pumps
Quick Links: