Queues

Queue problems are less common but it is still a data structure that is worth understanding well

Runtime analysis

Take note…

    • Check if can assume data structure is optimal

    • To optimize for Python, use from collections import deque instead to popleft()

Corner cases

  1. Empty queues

  2. Queue with one item

  3. 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