A Queue is a linear data structure that follows the First In, First Out (FIFO) principle, meaning the first element added to the queue will be the first one to be removed. It is commonly used in scenarios where order of processing is important, such as scheduling tasks or handling requests.
Time Complexity:
Enqueue: O(1) (adding an element)
Dequeue: O(1) (removing an element)
Front/Peek: O(1) (accessing the front element)
isEmpty: O(1)
Space Complexity:
O(n) (where n is the number of elements in the queue)
Queues can be implemented using arrays, linked lists, or circular buffers. They are widely used in various applications such as breadth-first search (BFS) in graphs, print job scheduling, and CPU task scheduling.