Cheatsheet

Collections across C#, Python, Java and C++

Equivalent built-in collections in four languages and what each common operation costs, taken from the tested collection encyclopedia.

Version 1 · updated 2026-11-24

Equivalents

  • .NET has no standard double-ended queue: Queue<T> is FIFO only, and LinkedList<T> gives O(1) ends with poor locality.
  • Python’s heapq is a set of functions on a plain list, not a class.
  • std::priority_queue is an adapter over std::vector and is a max-heap by default; the other three are min-heaps.
  • Java’s ArrayDeque serves as both queue and stack; prefer it to the legacy Stack class.

Dynamic array

Hash map

Hash set

Queue / deque

Queue / deque: time per operation
OperationC# · Queue<T>Python · collections.dequeJava · ArrayDeque<E>C++ · std::deque<T>
Add at the backO(1) amortized · O(n) worstO(1)O(1) amortized · O(n) worstO(1)
Remove from the frontO(1)O(1)O(1)O(1)
Peek at the frontO(1)—O(1)—

Priority queue

Priority queue: time per operation
OperationC# · PriorityQueue<TElement, TPriority>Python · heapqJava · PriorityQueue<E>C++ · std::priority_queue<T>
InsertO(1) best · O(log n) worstO(log n) amortizedO(log n)O(log n)
Remove the topO(log n)O(log n)O(log n)O(log n)
Peek at the topO(1)O(1)O(1)O(1)
Build from n itemsO(n)O(n)—O(n)

Reading the tables

amortized
Averaged over a sequence of operations; a single call can cost O(n) when the buffer grows.
expected / average
Over hash values (or random inputs). Hash tables degrade to O(n) when many keys collide.
worst
The encyclopedia’s worst case for that operation group. Some groups include a scanning variant (for example ContainsValue or RemoveWhere), which is where an O(n) comes from.
—
The encyclopedia does not list that operation for this collection. std::vector has no member search (use std::find, O(n)); Java sorts lists with List.sort / Collections.sort.

Every cell links to the operation page, which has the full complexity profile, its assumptions, memory effects and a tested example.

References