Data Structures19 sections · 729 units
Open in Course

Queue Implementation

Array or linked list

You can implement queues with:

1.1. Linked list: O(1)O(1) enqueue and dequeue, but more memory overhead.

2.2. Circular array: O(1)O(1) amortized, more cache-friendly. In practice, use the built-in: C++ has queue, Python has collections.deque (use append and popleft), Java has Queue interface with LinkedList. Don't implement from scratch in contests. Use the standard library. Time: O(1)O(1) per operation. Space: O(n)O(n).