List

OperationExampleBig-O
Indexl[i]O(1)
Storel[i] = 0O(1)
Lengthlen(l)O(1)
Appendl.append(x)O(1)
Popl.pop()O(1)
Slicel[a:b]O(b-a)
Constructionlist(x)O(len(x))
Checkl1 == l2O(len(n))
Insertl[a:b] = xO(n)
Containmentx in lO(n)
Copyl.copy()O(n)
Removel.remove()O(n)
Countl.count(x)O(n)
Indexl.index(x)O(n)
Popl.pop(i)O(n)
Extreme valuemin(l)/max(l)O(n)
Iterationfor v in l:O(n)
Reversel.reverse()O(n)
Sortl.sort()O(n Log n)
Multiplyk * lO(k n)

Set

OperationExampleBig-O
Lengthlen(s)O(1)
Adds.add(x)O(1)
Containmentx in sO(1)
Removes.remove()O(1)
Pops.pop()O(1)
Constructionset(x)O(len(x))
Checks1 == s2O(len(s))
Unions + tO(len(s)+len(t))
Intersections & tO(len(s)+len(t))
Differences - tO(len(s)+len(t))
Symmetric Diffs ^ tO(len(s)+len(t))
Iterationfor v in s:O(n)
Copys.copy()O(n)

Dictionary

OperationExampleBig-O
Indexd[k]O(1)
Stored[k] = vO(1)
Lengthlen(d)O(1)
Popd.pop()O(1)
Viewd.keys()O(1)
Constructiondict(x)O(len(x))
Iterationfor k in d:O(n)

Sort

MethodBestAverageWorst
Insertion SortO(n)O(n^2)O(n^2)
Selection SortO(n^2)O(n^2)O(n^2)
Bubble SortO(n^2)O(n^2)O(n^2)
Shell SortO(n)O(n^1.5)O(n^1.5)
Quick SortO(n log n)O(n log n)O(n^2)
Heap SortO(n log n)O(n log n)O(n log n)
Merge SortO(n log n)O(n log n)O(n log n)
Radix SortO(dn)O(dn)O(dn)
MethodSearchInsertDelete
SequentialO(n)O(1)O(n)
BinaryO(log n)O(log n + n)O(log n + n)
Binary Search Tree (Balanced)O(log n)O(log n)O(log n)
Binary Search Tree (Left-Associative)O(n)O(n)O(n)
Hashing (Best)O(1)O(1)O(1)
Hashing (Worst)O(n)O(n)O(n)

Heap

OperationExampleBig-O
Pushheapq.heappush(heap, x)O(log n)
Popheapq.heappop(heap)O(log n)
Constructionheapq.heapify(heap)O(n)

DFS/BFS

N은 노드, E는 간선일 때

  • 인접 리스트: O(N+E)
  • 인접 행렬: O(N^2)