VR

Complexity Cheat Sheet


Python Data Structures

Operationlistdictsetdeque
Access by indexO(1)N/AN/AO(1) ends, O(N) middle
SearchO(N)O(1) avgO(1) avgO(N)
Insert at endO(1) amortizedO(1) amortizedO(1) amortizedO(1)
Insert at frontO(N)N/AN/AO(1)
Delete by keyO(N)O(1) avgO(1) avgO(N)
Membership testO(N)O(1) avgO(1) avgO(N)

Go Data Structures

Operationslicemapchannel (buffered)
Access by indexO(1)O(1) avgN/A
Insert at end (append)O(1) amortizedO(1) amortizedO(1) if not full
Delete by keyO(N) shiftO(1) avgN/A
Range (for-range)O(N)O(N)O(N) until closed

Database Operations

OperationComplexityCondition
Point lookupO(log N)Index exists
Point lookup (no index)O(N)Full table scan
Range scanO(log N + K)Index exists, K=rows returned
Sort result setO(N log N)No index on sort column
JOIN (hash join)O(N+M)Planner chooses hash join
JOIN (nested loop)O(N×M)Small inner table or index
INSERTO(log N)Updates all indexes
UPDATE with indexO(log N) update + O(log N) indexPer updated index

Redis Operations

CommandComplexityNotes
GET/SETO(1)
MGET/MSETO(N)N = key count
HGET/HSETO(1)
HGETALLO(N)N = field count
LPUSH/RPUSHO(1)
LRANGEO(S+N)S = start offset
ZADDO(log N)
ZRANGEO(log N + K)K = elements returned
KEYS patternO(N)⚠ Never in production — blocks Redis
SCANO(1) per call, O(N) totalUse this instead of KEYS

HTTP / Network

ItemValue
TCP 3-way handshake1.5 RTT
TLS 1.3 handshake1 RTT
TLS 1.2 handshake2 RTT
DNS lookup (uncached)1 RTT to resolver + resolver's RTT to authoritative
HTTP/1.1 request1 RTT per request (no pipelining)
HTTP/2 request1 RTT for all multiplexed on established connection
gRPC (over HTTP/2)1 RTT for unary, streaming for streaming