What is Big O notation?
Why Interviewers Ask This
This question tests conceptual clarity. Interviewers want to hear a precise, confident definition before moving to more complex Data Structures & Algorithms topics. It also reveals how well you can explain technical ideas to non-experts.
Answer
Big O notation describes the upper bound of an algorithm's time or space complexity as the input size n grows toward infinity — it characterizes the worst-case growth rate, ignoring constants and lower-order terms. Common complexities (best to worst): O(1) — constant time: doesn't grow with input size. Hash map lookup, array index access; O(log n) — logarithmic: input is halved each step. Binary search, balanced BST operations; O(n) — linear: proportional to input. Linear search, traversing a list; O(n log n) — linearithmic: efficient sorting (merge sort, heapsort, quicksort average); O(n²) — quadratic: nested loops. Bubble sort, selection sort, naive matrix multiplication; O(2ⁿ) — exponential: brute-force combinatorial problems. Fibonacci naive recursion; O(n!) — factorial: permutations. Rules: drop constants (O(2n) → O(n)), drop lower-order terms (O(n² + n) → O(n²)), consider worst case. Space complexity: same notation for memory usage. Common interview question: "What is the time/space complexity of your solution?" Always analyze before and after optimization.
Pro Tip
This topic has Data Structures & Algorithms-specific nuances that differ from general programming. Highlighting those nuances in your answer shows expertise rather than generic knowledge.