#1 India's Top IT Training Institute
×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
Mentors

Mentors

Meet the industry experts who train and guide you through your course.

Read More →
Free Resources

Free Resources

Free tutorials, interview questions, tools and calculators to help you learn.

Explore →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
⚡ FREE · INSTANT SCORE

Big-O Complexity Quiz: 30 Practice Questions With Explanations

Pick a set, answer the Big-O questions and check your score with explanations.

  • 🔁 Loops and nested loops
  • 🌲 Recurrences and master theorem
  • 📚 Data structures and graphs

How to use the Big-O Complexity Quiz

  1. 1. Pick a setChoose loops, recurrences, or data structures and algorithms.
  2. 2. Answer the questionsSelect the tightest Big-O for each snippet or operation. You can skip any.
  3. 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.

More free tools

See all free tools