| description |
|---|
Queue problems are less common but it is still a data structure that is worth understanding well |
- Enqueue/offer:
$$O(1)$$ - Dequeue/poll:
$$O(1)$$ - Front:
$$O(1)$$ - Back:
$$O(1)$$ - isEmpty:
$$O(1)$$
- Built in data structure like
[]in Python use$$O(n)$$ , not$$O(1)$$ - Check if can assume data structure is optimal
- To optimize for Python, use
from collections import dequeinstead topopleft()
- Empty queues
- Queue with one item
- Queue with two items
Pop the queue and push back onto itself to bring the last element to the front