Data Structures & Algorithms practice
Data Structures & Algorithms · Cost & Arrays

Complexity Analysis: Practice Questions

100 questions. Try each one yourself before checking the answer.

Short on time? Filter by Must Do for the 25 questions that cover this topic on their own.

Q1Counting OperationsEasyMust Do

Before any notation: count how many times the work actually happens.

Q2Counting OperationsEasy

Count the operations in three different loop shapes.

Q3Growth ClassesEasy

How each growth class actually feels at n = 10, 1,000 and 1,000,000.

Q4Dropping ConstantsEasy

Why 2n and n are both called O(n).

Q5Dropping Lower TermsEasyMust Do

Why n^2 + n + 100 is just O(n^2).

Q6Formal DefinitionEasy

The actual definition of big-O, with a concrete witness.

Q7O, Omega, ThetaEasy

Three notations, three different claims.

Q8O(1)EasyMust Do

What constant time means — and what it does not.

Q9O(log n)Easy

Halving, and how few steps it really takes.

Q10O(n)Easy

Linear time, and how to recognise it.

Q11O(n log n)Easy

The sorting class, measured.

Q12O(n^2)EasyMust Do

Quadratic time, and the moment it becomes unusable.

Q13O(2^n)Easy

Exponential growth, without recursion.

Q14O(n!)Easy

Factorial time, and why brute-forcing orderings fails immediately.

Q15Comparing GrowthEasy

Put all the classes on one chart and find the crossovers.

Q16Best, Average, WorstEasyMust Do

The same algorithm has three different complexities.

Q17Best, Average, WorstEasy

Best case is not "small n", and worst case is a promise.

Q18Space ComplexityEasy

Memory has a complexity too.

Q19In-PlaceEasyMust Do

In-place versus allocating, and why it matters.

Q20Cost of List OperationsEasy

The complexity of every common list operation, measured.

Q21Cost of Dict & SetEasy

Dictionary and set operations, measured against lists.

Q22Cost of String OperationsEasy

Strings are immutable, and that changes every cost.

Q23Measuring TimeEasyMust Do

How to time code so the number means something.

Q24Measuring MemoryEasy

How to measure memory, and why getsizeof lies.

Q25Reading ComplexityEasyMust Do

A checklist for reading the complexity off unfamiliar code.

Q26Add vs MultiplyMediumMust Do

Sequential loops add; nested loops multiply. Apply the rule to eight functions.

Q27Loops That Are Not LinearMedium

Loops whose counter multiplies, divides, or skips.

Q28Triangular LoopsMedium

Inner loops whose bound depends on the outer variable.

Q29Two InputsMediumMust Do

When there are two inputs, n is not enough.

Q30Hidden LoopsMedium

The lines that look like one operation and are really a loop.

Q31Hidden LoopsMedium

.count() and .index() inside a comprehension.

Q32SlicingMedium

Slices copy, and copies inside loops are quadratic.

Q33String BuildingMediumMust Do

Building output: four approaches, two complexities.

Q34Front vs BackMedium

The two ends of a list have different costs, and it decides your data structure.

Q35Conversion CostsMedium

Converting between structures is never free.

Q36Sorting in a LoopMedium

sorted() inside a loop is the most expensive innocent line in Python.

Q37Built-in AggregatesMedium

min, max, sum, any, all — all O(n), and when that compounds.

Q38ComprehensionsMedium

Nested comprehensions, and reading their cost.

Q39Short-CircuitingMediumMust Do

any, all, and, or stop early — unless you stop them.

Q40Early ExitMedium

An early return improves the best case and never the worst.

Q41Composed FunctionsMedium

Working out the cost when functions call other functions.

Q42Amortised AnalysisMediumMust Do

Why list.append is O(1) when it sometimes copies everything.

Q43Amortised AnalysisMedium

Watch the resize happen, and what pre-sizing saves.

Q44Amortised vs AverageMedium

Three different kinds of "it is usually fast".

Q45Space vs TimeMedium

Spending memory to buy speed, measured both ways.

Q46Lazy EvaluationMedium

Generators: the same time, a fraction of the memory.

Q47Constant-Time OperationsMedium

Why len() is O(1), and what that tells you about the design.

Q48Container ChoiceMedium

Membership testing: the measurement that fixes the most code.

Q49Same Output, Different CostMedium

One problem, five correct solutions, a hundredfold apart.

Q50Reference CardMediumMust Do

The complexity of every Python operation you will use in this track.

Q51Choosing From a ConstraintMediumMust Do

The required complexity tells you which approach to use before you write any code.

Q52Duplicate DetectionMedium

Four ways to find duplicates, and how the constraint picks one.

Q53Set IntersectionMedium

Finding what two collections have in common.

Q54Frequency CountingMedium

Counting: five approaches, and where each belongs.

Q55Top KMedium

Finding the largest k, and why sorting is usually the wrong tool.

Q56Anagram CheckingMedium

Sorting versus counting, and when each wins.

Q57Lookup StructuresMediumMust Do

Turning a repeated search into a single index build.

Q58Matrix ComplexityMedium

Grids: why O(n^2) is usually the wrong way to say it.

Q59Output-Sensitive CostMedium

When the cost depends on the size of the ANSWER, not the input.

Q60When n Is SmallMediumMust Do

O(n^2) is often the right answer.

Q61Constant FactorsHard

Find the crossover where the better complexity actually wins.

Q62PreprocessingHardMust Do

Pay once, query many times.

Q63Time-Space TradeoffHard

Measure both axes and choose deliberately.

Q64CachingHard

Caching changes the complexity of a workload, not of a function.

Q65Analysing Real CodeHard

Work out the complexity of a function you did not write.

Q66EstimatingHardMust Do

Predict the runtime before you write the code.

Q67Back of the EnvelopeHard

The numbers worth memorising.

Q68When Complexity Is IrrelevantHard

Sometimes the algorithm is not the bottleneck at all.

Q69Reading a ProfileHard

Let the profiler tell you where the time goes.

Q70When Not to OptimiseHard

The most valuable optimisation decision is often "no".

Q71Accidental QuadraticHardMust Do

Six functions with one visible loop each. Three are quadratic.

Q72Accidental QuadraticHard

Growing a result: the three ways it goes quadratic.

Q73Accidental QuadraticHard

Consuming a collection from the wrong end.

Q74Accidental QuadraticHard

Recomputing an aggregate that could be maintained.

Q75Failed OptimisationHard

Four "optimisations" that made things slower.

Q76Destroyed Short-CircuitingHardMust Do

Code that could stop early and does not.

Q77Misreading LoopsHard

Nested loops that are not quadratic, and flat loops that are.

Q78Worst-Case DegradationHardMust Do

When O(1) average becomes O(n), on purpose.

Q79Hidden Memory CostHard

Code whose time complexity is fine and whose memory is not.

Q80Latency vs ThroughputHard

Amortised O(1) can still stall.

Q81Same Class, Different SpeedHard

Two O(n) functions that differ by 50x.

Q82Reading Unfamiliar CodeHard

Ten functions, no labels. State the complexity of each.

Q83Misleading BenchmarksHard

Five benchmarks that report the wrong answer.

Q84Debugging SlownessHard

A slow function, diagnosed end to end.

Q85Complexity ReviewHard

Review a module the way you would review a colleague's pull request.

Q86Mini-Project — Benchmark HarnessMini-ProjectMust Do

Build the measuring tool you will use for the rest of this track.

Q87Mini-Project — Growth VisualiserMini-Project

Plot growth curves in the terminal.

Q88Mini-Project — Operation CounterMini-Project

Count operations instead of timing them.

Q89Mini-Project — Space ProfilerMini-Project

Measure what data structures actually cost.

Q90Mini-Project — Complexity QuizMini-ProjectMust Do

Build a self-testing quiz that generates functions and checks your answer.

Q91Mini-Project — Crossover FinderMini-Project

Find the input size where one implementation overtakes another, then build a hybrid.

Q92Mini-Project — Regression DetectorMini-Project

Catch a performance regression before it ships.

Q93Mini-Project — Cost ModelMini-Project

Predict a program's runtime from a model, then check the prediction.

Q94Mini-Project — Complexity ReportMini-Project

Generate a complexity report card for a module.

Q95Mini-Project — Doubling ExperimentMini-Project

Infer a complexity from a black box you cannot read.

Q96Explaining ComplexityInterview

Explain big-O to three different audiences.

Q97Diagnosing SlownessInterview

"The dashboard got slow." Work the problem.

Q98Design Under ConstraintInterview

Design a data structure to meet stated complexity bounds.

Q99Mock InterviewInterview

A complexity-focused interview, transcribed.

Q100CapstoneInterviewMust Do

Take a slow, working module and make it fast, provably.

Stuck? Solve it with a mentor.

Your first 1-on-1 session is free.

Book my free session