DSA · Patterns, not puzzles

What is Big O notation and why does it matter?

Easybig-ocomplexityanalysisUpdated Oct 2026
Quiz this track

Short answer

Big O describes how an algorithm's time or space grows as the input size grows, ignoring constants and lower-order terms. It compares scalability rather than exact runtime on one machine.

Big O answers one question: when the input gets larger, how does the work grow? A function that doubles its work when the input doubles is linear. A function with nested iterations over the same input is quadratic. Constants and small terms are dropped because they stop mattering as the input becomes large.

The growth rates you should recognise

  • O(1): constant time, such as reading an array index
  • O(log n): halving the search space, such as binary search
  • O(n): one pass over the input
  • O(n log n): comparison sorting
  • O(n^2): nested loops over the same input
  • O(2^n): exploring every subset
js
function containsDuplicate(values) {
  for (let i = 0; i < values.length; i++) {
    for (let j = i + 1; j < values.length; j++) {
      if (values[i] === values[j]) return true;
    }
  }
  return false;
}
The outer and inner loops both scale with the input, so this is O(n^2).

You can often improve the complexity by changing the data structure. A hash set turns the duplicate check into one pass, giving O(n) time at the cost of O(n) space. That trade-off is usually the real interview discussion.

Big O is not a benchmark. Two O(n) implementations can differ by a large constant factor. Use it to reject algorithms that will not scale, then measure when constants matter.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1What is the difference between Big O, Big Omega and Big Theta?
  2. 2Why do we drop constants and lower-order terms?
  3. 3What is the complexity of the hash set version of this function?
  4. 4When does Big O fail to predict real performance?

Say it in the interview

Big O describes how the work grows as the input grows, not the exact number of milliseconds. I drop constants and lower-order terms because the dominant term decides the trend. For example, nested loops over the same array are quadratic, while a single pass with a hash set is linear. The notation helps me reject approaches that will not scale, but I still measure when constant factors matter.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live DSA mock interview and get scored feedback on depth, clarity and confidence.