InfoparkDailyCAREER TOOLS

DSA · Lesson 1 of 9

Big-O & complexity

Measuring how time and memory grow with input size.

Interviewers care less about whether code works on 5 items and more about how it behaves on 5 million. Big-O describes how the number of steps grows as the input size n grows, ignoring constants.

Big-ONameTypical example
O(1)ConstantRead arr[i], dict lookup
O(log n)LogarithmicBinary search
O(n)LinearOne loop over the data
O(n log n)LinearithmicGood sorting algorithms
O(n²)QuadraticNested loops over the same data
O(2ⁿ)ExponentialTrying every subset

Space complexity counts extra memory the same way. Always state both, e.g. “O(n) time, O(1) extra space”.

Try it yourself

Press Run to see the output.

Edit and press Run (or Ctrl/⌘ + Enter). Python runs in your browser — the first run downloads the Python engine and takes a few seconds.

Key points

  • Big-O = growth rate, constants dropped.
  • Nested loops over n items ≈ O(n²).
  • A set/dict often turns O(n²) into O(n).

Quick check

What is the time complexity of binary search?

Practice task

Change the data size to 6000 and compare: the slow version should take roughly 4× longer, the fast one about 2×. Explain why.

Interview corner

What's the complexity of two separate (not nested) loops over n?

O(n) + O(n) = O(2n), which simplifies to O(n).

Is O(n log n) always slower than O(n²)?

No — for large n, O(n log n) grows much more slowly. For tiny inputs constants can dominate, which is why some libraries switch to insertion sort for small arrays.

Further reading

Official documentation, linked for deeper study. These are outside sites; this lesson's text is our own.

Original lesson written by the InfoparkDaily team · © 2026 InfoparkDaily · Free to learn — no paid course or subscription.