Unit No.6 Queue
Unit No.6 Queue
• A Queue is an abstract data type that follows the First In First Out
(FIFO) principle, meaning that the first element added to the queue
will be the first one to be removed. This behavior can be compared to
a line of people waiting for service: the first person in line is the first
to be served.
Key Characteristics
• Enqueue: Adding an element to the back of the queue.
• Dequeue: Removing an element from the front of the queue.
• Peek: Retrieving the front element without removing it.
• Empty: Checking if the queue is empty.
Queue as Abstract Data Type (ADT)
• A Queue ADT defines the operations that can be performed on a
queue without specifying how these operations are implemented.
The main operations typically include:
• Enqueue: Add an element to the back.
• Dequeue: Remove an element from the front.
• Front: Return the front element.
• isEmpty: Check if the queue is empty.
• Size: Return the number of elements in the queue.
Representation of Queue Using
Sequential Organization
• Challenges
• Fixed Size: The size of the queue is fixed at initialization.
• Inefficient Space Utilization: If elements are dequeued, the front
indices may leave unused space.
Queue Operations
Circular Queue and Its Advantages
• A Circular Queue is an improvement over the simple queue
implementation. It connects the last position back to the first position
to make use of the free space created by dequeued elements.
Advantages
• Efficient Use of Space: There is no wasted space as in a linear queue
implementation.
• Simple Logic: The circular logic makes it easier to manage the front
and rear indices.
Each queue can be managed independently, and they can share the same array space
. Linked Queue and Operations