DSA Interview Question

What is Big O notation?

Updated 2026-07-10 · Beginner friendly
Quick answer

Big O notation describes how the running time or memory of an algorithm grows as the input gets larger. It focuses on the worst case and ignores constants, so it captures the overall trend rather than exact timings. For example O(n) means the work grows in line with the input size, and O(1) means the work stays constant no matter the size.

Why we use it

Two algorithms can both solve a problem, but one may be far slower on large inputs. Big O gives us a simple language to compare them without depending on the machine or the programming language.

Common complexities from fast to slow

# O(n): one loop over n items
for x in items:
    print(x)

# O(n squared): a loop inside a loop
for a in items:
    for b in items:
        print(a, b)
In the interview

Always state the time and the space complexity when you finish a solution, even if the interviewer does not ask. Saying this runs in O(n) time and O(1) extra space shows maturity and often earns extra credit.

Want the full DSA guide?

Read every DSA concept with notes, diagrams, and code in one place. Track your progress as you go.

Open the DSA guide All DSA questions