Identify real-world scheduling problems suited to queues.
02
Lesson notes
A queue is a linear structure in which insertion normally occurs at the rear and removal at the front. The first item added is the first one removed, so the queue follows First In, First Out (FIFO). It models fair waiting lines: a customer who arrived earlier should normally be served earlier.
Enqueue adds an item to the rear. Dequeue removes and returns the front item. Front or peek reads the next item without removing it. A queue can be implemented with a linked structure or a circular array; repeatedly deleting index zero from a Python list is simple to demonstrate but inefficient for a large queue because later elements must shift.
A circular queue treats the final position of an array as connected back to the first. Front and rear indices wrap around using modulo arithmetic. This reuses empty positions left by earlier dequeues, avoiding the wasted-space problem of a simple fixed array that only moves its rear pointer forward.
Queues are used in printer jobs, network packet handling, customer-support systems, CPU scheduling and breadth-first search. Different applications may use priority queues, where removal is based on priority rather than arrival order; that is a different scheduling policy from a standard FIFO queue.
03
Worked code examples
Worked example
deque provides efficient insertion at the rear and removal from the front, preserving FIFO order.