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
| Concept | C# | Python | Java | C++ |
|---|---|---|---|---|
| Dynamic array | List<T> | list | ArrayList<E> | std::vector<T> |
| Hash map | Dictionary<TKey, TValue> | dict | HashMap<K, V> | std::unordered_map<Key, T> |
| Hash set | HashSet<T> | set | HashSet<E> | std::unordered_set<Key> |
| Queue / deque | Queue<T> | collections.deque | ArrayDeque<E> | std::deque<T> |
| Priority queue | PriorityQueue<TElement, TPriority> | heapq | PriorityQueue<E> | std::priority_queue<T> |
- .NET has no standard double-ended queue:
Queue<T>is FIFO only, andLinkedList<T>gives O(1) ends with poor locality. - Python’s
heapqis a set of functions on a plainlist, not a class. std::priority_queueis an adapter overstd::vectorand is a max-heap by default; the other three are min-heaps.- Java’s
ArrayDequeserves as both queue and stack; prefer it to the legacyStackclass.
Dynamic array
| Operation | C# · List<T> | Python · list | Java · ArrayList<E> | C++ · std::vector<T> |
|---|---|---|---|---|
| Append at the end | O(1) amortized · O(n) worst | O(1) amortized · O(n) worst | O(1) amortized · O(n) worst | O(1) amortized · O(n) worst |
| Insert at an index | O(1) best · O(n) worst | O(1) best · O(n) worst | O(1) best · O(n) worst | O(1) best · O(n) worst |
| Remove at an index | O(1) best · O(n) worst | O(1) best · O(n) worst | O(1) best · O(n) worst | O(1) best · O(n) worst |
| Read or write by index | O(1) | O(1) best · O(k) worst | O(1) | O(1) |
| Search by value | O(n) average | O(n) average | O(n) average | — |
| Sort in place | O(n log n) average | O(n) best · O(n log n) worst | — | — |
Hash map
| Operation | C# · Dictionary<TKey, TValue> | Python · dict | Java · HashMap<K, V> | C++ · std::unordered_map<Key, T> |
|---|---|---|---|---|
| Insert or update | O(1) amortized · O(n) worst | O(1) amortized · O(n) worst | O(1) amortized · O(n) worst | O(1) average · O(n) worst |
| Look up by key | O(1) expected · O(n) worst | O(1) average · O(n) worst | O(1) expected · O(n) worst | O(1) average · O(n) worst |
| Contains key | O(1) expected · O(n) worst | O(1) average · O(n) worst | O(1) expected · O(n) worst | O(1) average · O(n) worst |
| Remove by key | O(1) expected · O(n) worst | O(1) average · O(n) worst | O(1) expected · O(n) worst | O(1) average · O(n) worst |
Hash set
| Operation | C# · HashSet<T> | Python · set | Java · HashSet<E> | C++ · std::unordered_set<Key> |
|---|---|---|---|---|
| Add | O(1) amortized · O(n) worst | O(1) amortized · O(n) worst | O(1) amortized · O(n) worst | O(1) average · O(n) worst |
| Contains | O(1) expected · O(n) worst | O(1) average · O(n) worst | O(1) expected · O(n) worst | O(1) average · O(n) worst |
| Remove | O(1) expected · O(n) worst | O(1) average · O(n) worst | O(1) expected · O(n) worst | O(1) average · O(n) worst |
Queue / deque
| Operation | C# · Queue<T> | Python · collections.deque | Java · ArrayDeque<E> | C++ · std::deque<T> |
|---|---|---|---|---|
| Add at the back | O(1) amortized · O(n) worst | O(1) | O(1) amortized · O(n) worst | O(1) |
| Remove from the front | O(1) | O(1) | O(1) | O(1) |
| Peek at the front | O(1) | — | O(1) | — |
Priority queue
| Operation | C# · PriorityQueue<TElement, TPriority> | Python · heapq | Java · PriorityQueue<E> | C++ · std::priority_queue<T> |
|---|---|---|---|---|
| Insert | O(1) best · O(log n) worst | O(log n) amortized | O(log n) | O(log n) |
| Remove the top | O(log n) | O(log n) | O(log n) | O(log n) |
| Peek at the top | O(1) | O(1) | O(1) | O(1) |
| Build from n items | O(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
ContainsValueorRemoveWhere), which is where an O(n) comes from. - —
- The encyclopedia does not list that operation for this collection.
std::vectorhas no member search (usestd::find, O(n)); Java sorts lists withList.sort/Collections.sort.
Every cell links to the operation page, which has the full complexity profile, its assumptions, memory effects and a tested example.