Queues
Queue problems are less common but it is still a data structure that is worth understanding well
Runtime analysis
Enqueue/offer:
Dequeue/poll:
Front:
Back:
isEmpty:
Take noteβ¦
Built in data structure like
[]
in Python use , notCheck if can assume data structure is optimal
To optimize for Python, use
from collections import deque
instead topopleft()
Corner cases
Empty queues
Queue with one item
Queue with two items
Techniques
Rotating the queue on itself
Pop the queue and push back onto itself to bring the last element to the front
Last updated