# Queues

## Runtime analysis

1. Enqueue/offer: $$O(1)$$
2. Dequeue/poll: $$O(1)$$
3. Front: $$O(1)$$
4. Back: $$O(1)$$
5. isEmpty: $$O(1)$$

## Take note…

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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://interviews.woojiahao.com/data-structures/queues.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
