What is a Queue?
A Queue is a linear data structure that follows the FIFO (First In, First Out) principle. This means that the first element added to the queue will be the first one to be removed. It is similar to a real-life line of people waiting for a ticket; the person who arrives first gets served first.
Time Complexity
- Enqueue (Insertion)O(1)
- Dequeue (Deletion)O(1)
- Peek (Front Item)O(1)
- SearchO(n)
Real-World Applications
- ✓Task SchedulingOperating systems use queues to manage processes waiting for CPU time.
- ✓Breadth-First Search (BFS)Queues are essential for graph traversal algorithms like BFS to explore neighbors layer by layer.
- ✓PrintersPrint jobs are stored in a queue and processed in the order they were received.