How to use the Big-O Complexity Quiz
- 1. Pick a setChoose loops, recurrences, or data structures and algorithms.
- 2. Answer the questionsSelect the tightest Big-O for each snippet or operation. You can skip any.
- 3. Check your scoreSee your score, the correct answers and a short reason for every question.
How to find the Big-O of code
Big-O describes how running time grows with input size n, ignoring constants and lower-order terms. A few rules solve most exam questions:
- Simple loops that step by 1 up to n are O(n). Nested loops multiply, and loops one after another add.
- A loop variable that doubles or halves runs O(log n) times. One that squares (i = i × i) runs O(log log n) times.
- An inner loop bounded by a constant does not change the order.
- A geometric sum such as n + n/2 + n/4 + … is O(n), not O(n log n).
For recurrences of the form T(n) = aT(n/b) + f(n), compare f(n) with nlogba. That is the master theorem.
Worked examples
for (i = 1; i < n; i *= 2) runs for i = 1, 2, 4 … up to n, which is about log2 n times. So it is O(log n). Put it inside a loop that runs n times and the total is O(n log n).
Merge sort has T(n) = 2T(n/2) + n. Here a = 2 and b = 2, so nlog22 = n. That matches f(n), so case 2 gives O(n log n). With T(n) = 8T(n/2) + n², log28 = 3 is greater than 2, so the answer is O(n³). Work out exact iteration counts with the time complexity calculator.
About these questions
These are practice questions written for revision. They are not past interview or exam questions. The answers give the standard worst-case bound unless the question says average or best case. For a quick lookup table, see the Big-O cheat sheet. For wider practice, take the DSA MCQ quiz.
Frequently asked questions
Is Big-O the worst case?
Big-O is an upper bound. In these questions it is used for the worst case unless the question says average or best case.
Why is n + n/2 + n/4 + … only O(n)?
It is a geometric series with ratio 1/2, so the sum stays below 2n.
Are these real interview questions?
No. They are practice questions written to cover common patterns. They are not taken from any company's interviews.
Can I retake a set?
Yes. Change your answers and check again, or switch to another set.