■ Complete Notes on Queue (Data Structure)
1. Definition of Queue
A Queue is a linear data structure that stores elements in sequential order.
It follows FIFO (First In, First Out) principle: the element inserted first is removed first.
Insertion happens at rear, deletion at front.
Real-life example: people standing in line at a ticket counter.
2. Characteristics of Queue
- Linear structure.
- FIFO principle.
- Two ends: front (deletion) and rear (insertion).
- Homogeneous elements.
- Restricted access (only front and rear can be accessed).
- Can be fixed (array) or dynamic (linked list).
3. Real-Life Examples of Queue
- Ticket line at a counter.
- Printer queue (documents printed in order).
- Call center (calls answered in order).
- Order processing system.
- Traffic lights (vehicles pass in order).
4. Operations on Queue
- Enqueue (insert at rear).
- Dequeue (delete from front).
- Peek (front element without deletion).
- isEmpty (check if queue is empty).
- isFull (check if queue is full).
5. Queue Representation
- Array representation: uses indices for front and rear.
- Linked list representation: dynamic, no memory wastage.
6. Overflow and Underflow in Queue
- Overflow: inserting into a full queue.
- Underflow: deleting from an empty queue.
7. Types of Queues
7.1 Linear Queue: Basic FIFO, problem of memory wastage in arrays.
7.2 Circular Queue: Connects last position back to first, avoids wastage. Uses (rear+1)%size.
7.3 Double-Ended Queue (Deque): Insert/delete at both ends. Input restricted or Output restricted
types.
7.4 Priority Queue: Elements served by priority, not strictly FIFO.
8. Advantages of Queue
- Fair order of processing (FIFO).
- Useful in scheduling and resource sharing.
- Prevents starvation in simple FIFO.
- Common in real systems.
9. Disadvantages of Queue
- Limited access (only front and rear).
- Memory wastage in linear array queues.
- No random access possible.
- More complex in circular/priority queues.
10. Applications of Queue
- CPU scheduling.
- Printer spooling.
- Call center systems.
- Order processing.
- Buffering (temporary data storage).
- Tree traversals (level order).
- Disk scheduling (I/O management).