Octonote AI
Make your own →

Big-O for everyday data structures

Sunil Tiwari· Oct 12, 2026 · 1 min

Inline math and code mixed into plain text — e.g. a hash map lookup is O(1)O(1) on average and you call it with map.get(key).

Arrays and lists

  • Index access a[i]: O(1)O(1)
  • Search unsorted: O(n)O(n) · search sorted (binary search): O(log⁡n)O(\log n)
  • Insert at end (dynamic array): amortised O(1)O(1) · insert at front: O(n)O(n)

Hash maps

  • Get / put / delete: O(1)O(1) average, O(n)O(n) worst case when everything collides.

Trees and heaps

  • Balanced BST search / insert / delete: O(log⁡n)O(\log n)
  • Heap push / pop: O(log⁡n)O(\log n) · peek: O(1)O(1)

Sorting

  • Merge sort, heap sort: O(nlog⁡n)O(n \log n) always.
  • Quick sort: O(nlog⁡n)O(n \log n) average, O(n2)O(n^2) worst.
  • Counting sort: O(n+k)O(n + k) when keys are small integers.

Growth at a glance

For n=106n = 10^6: log⁡n≈20\log n \approx 20, nlog⁡n≈2×107n \log n \approx 2 \times 10^7, n2=1012n^2 = 10^{12} — the difference between milliseconds and days.

Was this useful?
Written bySunil TiwariMore from Octonote examples →
Notes and canvases, together.This page was made with Octonote AI. Publish your own in one click.
Get started free