Queues in Python
Queues in Python
O
O
D
T
E
C
Queues in
H
Python
Understanding and Implementing Queues
01
Basics on Queue
What is a Queue?
A queue is a data structure that follows
the First-In-First-Out (FIFO) principle,
where elements are added at the back
and removed from the front. It models
real-world scenarios like waiting lines
Queues
❑ Linear data structure which stores its element in an ordered
manner
❑ It has two pointers , ‘Front’ that points to the beginning of
the queue and ‘Rear’ that points to the end of the queue
❑ A queue works on a FIFO [First-in-First-Out] principle
➢ The first element added to the queue is the first one to be
removed
❑ The element in a queue are added at one end and removed
from the other end
❑ In Computer system the OS makes fuel use Queues
Real-Life Examples of Queues
❑ People moving on an escalator
❑ People waiting for a bus
❑ People standing outside the ticketing window of
cinema hall
❑ Luggage kept on conveyor belts
❑ Cars lined at a roll bridge
02
Types of Queues
1.Simple/Linear Queue
❑ A linear queue is a type of queue where data elements
are added to the end of the queue and removed from the
front of the queue
❑ Linear queues are used in applications where data
elements need to be processed in the order in which they
are received
❑ Examples:
➢ Ticket Counter: The first person in line gets served first
➢ Printer Queue: Jobs are printed in the order they were submitted
1.Simple/Linear Queue
❑ Operations:
➢ Enqueue: Adding an element to the rear of the queue
➢ Dequeue: Removing an element from the front of the
queue
Code:
q = []
q.append('apple’)
q.append('banana’)
print(q.pop(0)) # apple goes out
Explanation:
Round table
Circular Queue Goes in a circle
passing items