A Queue is an ordered collection of items from which items may be deleted at one end (called the front of the queue) and into which items may be inserted at the other end (the rear of the queue).
Queue follows First-In-First-Out (FIFO) methodology, i.e. the first element inserted into the queue is the first element to be removed.
E.g.
A real-world example of the queue can be a single-lane one-way road, where the vehicle enters first, and exits first. More real-world examples can be seen as queues at the ticket windows and bus stops.
Fig: Waiting Queue
Applications of Queue
Due to the fact that queue performs actions on first in first out basis which is quite fair for the ordering of actions. There are various applications of queues discussed as below.
- Queues are widely used as waiting lists for a single shared resource like printer, disk, CPU.
- Queues are used in asynchronous transfer of data (where data is not being transferred at the same rate between two processes) for eg. pipes, file IO, sockets.
- Queues are used as buffers in most of the applications like MP3 media player, CD player, etc.
- Queue are used to maintain the play list in media players in order to add and remove the songs from the play-list.
- Queues are used in operating systems for handling interrupts.
Complexity
Data Structure |
Time Complexity |
Space Compleity |
|||||||
Average |
Worst |
Worst |
|||||||
Access |
Search |
Insertion |
Deletion |
Access |
Search |
Insertion |
Deletion |
||
Queue |
θ(n) |
θ(n) |
θ(1) |
θ(1) |
O(n) |
O(n) |
O(1) |
O(1) |
O(n) |
0 Comments