Question presented to candidate: "Explain Big-O notation to me as if I had never heard of it. Then look at a few loops written in Python and tell me their Big-O, and explain why we are allowed to drop constants."
What a strong answer should cover:
- Big-O describes how running time (or memory) grows as the input size n grows; it is about the shape of the growth, not seconds.
- Drop constant factors and lower-order terms: 3n² + 5n + 20 is O(n²); 2n is O(n).
- The common classes in order, with an example each: O(1) index, O(log n) binary search, O(n) one pass, O(n log n) good sorting, O(n²) all pairs, O(2ⁿ) all subsets.
- Reading code: sequential steps add, nested loops multiply, halving gives log n; Big-O is an upper bound and usually quoted for the worst case (Theta and Omega for tight and lower bounds).
- Python-specific hidden costs:
x in listis O(n) whilex in setand dict lookups are O(1) on average;list.pop(0)and slicing are O(n);sort()is O(n log n).
Code / implementation expected: Optional — a few Python functions whose loops the candidate labels O(1), O(log n), O(n), O(n²).