PyDSAWHY Engine
Python Hardware Complexity Reference

Big-O & Memory Complexity Cheatsheet

Time and space complexity lookup matrix for Python built-in data structure operations with underlying CPython explanations.

Data StructureOperationTime ComplexitySpace ComplexityWHY Under The Hood
Listarr[i] (Indexing)O(1)O(1)Direct memory pointer calculation: Base + (i * 8 bytes)
Listarr.append(x)O(1) AmortizedO(1)Over-allocates memory slots using (N >> 3) formula
Listarr.insert(0, x)O(N)O(1)Shifts all N existing elements 1 slot right in memory
Listarr.pop(0)O(N)O(1)Shifts all N-1 remaining elements 1 slot left in memory
Listx in arr (Search)O(N)O(1)Unindexed linear memory sweep item by item
Setx in set (Search)O(1) AmortizedO(N)Computes hash(x) & mask to jump straight to hash bucket
Setset.add(x)O(1) AmortizedO(1)Places pointer reference directly in hash bucket index
Dictdict[key] (Lookup)O(1) AmortizedO(N)PyDictObject sparse index table offset jump
Dequedeque.popleft()O(1)O(1)Doubly-linked 62-element block ring node pointer update
Built-insorted(arr)O(N log N)O(N)Timsort algorithm leveraging contiguous run runs