By the end of this chapter you'll be able to…

  • 1State what asymptotic notation claims and what it deliberately discards
  • 2Explain why an asymptotically better algorithm can be slower in practice
  • 3Distinguish the five notations and their formal definitions
  • 4Explain the role of the two constants in the definition of O
  • 5Explain why an upper bound need not be tight
  • 6Distinguish best, average and worst case from the notation itself
  • 7Recall the growth hierarchy from constant to n to the n
  • 8Apply the polynomial-beats-polylog and exponential-beats-polynomial rules
  • 9Explain why logarithm bases are irrelevant but exponential bases are not
  • 10Compare functions by taking logarithms when the hierarchy does not settle it
  • 11Count iterations for additive, multiplicative and squaring loop counters
  • 12Analyse nested loops whose inner bound depends on the outer counter
  • 13Read a divide-and-conquer recurrence directly from code
  • 14Apply the substitution method and strengthen a failing hypothesis
  • 15Build a recursion tree and sum work level by level
  • 16State the critical exponent and what it represents
  • 17Apply all three master-theorem cases including the regularity condition
  • 18Recognise when the master theorem does not apply and why
  • 19Solve the standard gap case by recursion tree
  • 20Distinguish amortised analysis from average-case analysis
  • 21Apply the aggregate, accounting and potential methods
  • 22Explain why doubling gives constant amortised appends and fixed increment does not
💡
Why this chapter matters in GATE
Every other algorithms chapter depends on this one, because every claim about an algorithm's cost is stated in asymptotic notation and most are derived from a recurrence. Asymptotic notation is a statement about growth, not about speed: saying an algorithm is quadratic says nothing about whether it takes a microsecond or an hour on a particular input, only that the time grows no faster than the square as the input grows without bound. The notation deliberately discards constants and lower-order terms because those depend on the machine, the compiler and the implementation while the growth rate depends on the algorithm, and discarding them is what makes the claim portable. That discarding has a cost worth stating plainly: an n log n algorithm can be slower than a quadratic one on every input you will ever run, if its constant is large enough. The second organising fact is that a recursive algorithm's cost is a recurrence read directly off the code — count the calls, note the subproblem size, add the outside work.

Before you start — revise these

🔗
Programming in C & Recursion
Reading a recurrence from a recursive function, and the distinction between total calls and stack depth, are developed there.
🔗
Discrete Mathematics
Solving linear recurrences by characteristic equation, summing geometric and harmonic series, and induction proofs are all used directly.
🔗
Calculus
Comparing growth rates by L'Hopital's rule and by taking logarithms uses the limit machinery from that chapter.

Asymptotic Complexity & Recurrences

Every other algorithms chapter depends on this one, because every claim about an algorithm's cost is stated in asymptotic notation and most of them are derived from a recurrence.

Asymptotic notation is a statement about growth, not about speed. Saying an algorithm is says nothing about whether it takes a microsecond or an hour on any particular input. It says that as the input grows without bound, the running time grows no faster than the square.

The notation deliberately discards constants and lower-order terms, because those depend on the machine, the compiler and the implementation, while the growth rate depends on the algorithm. Discarding them is what makes the claim portable.

That discarding has a cost worth stating plainly. An algorithm can be slower than an one on every input you will ever run, if its constant is large enough. Asymptotics tell you which wins eventually, not which wins today.

The second organising fact is that a recursive algorithm's cost is a recurrence, and a recurrence is read directly off the code. Count the recursive calls, note the subproblem size, add the work outside the calls. Everything after that is solving.

1. The Five Notations

Each notation bounds a function in a different direction, and the distinction is examined directly.

NotationMeaningAnalogy
Grows no faster than At most
Grows no slower than At least
Grows exactly like Exactly
Grows strictly slower than Less than
Grows strictly faster than Greater than

Formally, means there exist positive constants and such that

for all .

The two constants are what make the definition work. The constant absorbs any multiplicative factor and allows the bound to fail for small inputs, which is exactly why lower-order terms are irrelevant.

is both and simultaneously, so proving a tight bound means proving two inequalities rather than one.

Two remarks catch people out. is an upper bound and need not be tight, so writing that insertion sort is is technically true and useless. And describes a function, not an algorithm, so an algorithm has different bounds for best, average and worst case, and stating one without saying which is ambiguous.

The relation is not symmetric, so writing is meaningless. The equals sign here is a historical abuse of notation for set membership.

2. Comparing Growth Rates

The hierarchy is worth memorising, because most questions are asking where a function sits in it.

Three rules settle almost every comparison.

Any polynomial beats any polylogarithm. eventually overtakes , however absurd that looks for practical .

Any exponential beats any polynomial. eventually overtakes .

The base of a logarithm is irrelevant, since changing base multiplies by a constant, which absorbs. So and are both . The base of an exponential is not irrelevant: and differ by an exponential factor, not a constant.

When the hierarchy does not settle a comparison directly, take logarithms of both functions and compare those, or apply L'Hopital's rule to the ratio.

A common trap is against . Taking logarithms gives against , and the second is larger, so grows faster.

3. Analysing Loops

For iterative code, count how many times the innermost statement executes.

A loop running from 1 to with a constant increment executes times. A loop that multiplies its counter by a constant executes times, because the counter reaches after about multiplications.

Nested loops multiply when independent, but not when the inner bound depends on the outer counter.

For an inner loop running to the outer counter, the total is the sum , which is — the same as two independent loops, but the constant is halved.

A loop whose counter is squared each time executes times, since the exponent doubles and reaching needs doublings.

Conditional work inside a loop is bounded above by the worst case, but a tighter analysis sometimes shows the worst case cannot happen on every iteration — which is where amortised analysis begins.

4. Recurrences: Substitution and Recursion Trees

A recurrence for a divide-and-conquer algorithm has the shape , where is the number of subproblems, their size, and the work of dividing and combining.

The substitution method guesses a bound and proves it by induction. It is the only fully general method and the only one that produces a proof, but it requires the guess.

A frequent failure is to guess correctly and still fail the induction because the inductive hypothesis is too weak. Strengthening the hypothesis by subtracting a lower-order term often rescues it, which feels backwards and is standard practice.

The recursion tree method draws the recursion and sums the work level by level. It is the reliable way to generate the guess that substitution then proves.

At level there are nodes, each of size , so the work at that level is . The tree has levels, and the leaves number .

Three outcomes are possible and they correspond exactly to the three master-theorem cases. Either the root dominates, or the leaves dominate, or every level contributes equally.

5. The Master Theorem

For with and , compare against .

That exponent is the critical quantity, and it is the total work at the leaves of the recursion tree.

CaseConditionResult
1
2,
3 and regularity

Case 1 is leaf-dominated: the work shrinks going down the tree so fast that the leaves carry it all. Case 3 is root-dominated: the top level carries it all. Case 2 is balanced: every level contributes the same, and the extra logarithm counts the levels.

Case 3 carries a regularity condition that for some , which ensures the work genuinely shrinks going down. It holds for every polynomial that appears in practice and is checked only when is unusual.

The theorem does not always apply. If is larger than but not polynomially larger — by a factor of only , say — then no case fits, and a recursion tree is required.

The standard example of that gap is , which falls between cases 1 and 2.

6. Amortised Analysis

Amortised analysis bounds the average cost per operation over a worst-case sequence. It is not average-case analysis, because no probability is involved: the bound holds for every sequence, not for a typical one.

Three methods give the same answer with different bookkeeping.

The aggregate method bounds the total cost of operations and divides by . It is the simplest and is usually enough.

The accounting method charges each operation more than it costs and banks the surplus to pay for later expensive operations, requiring only that the balance never goes negative.

The potential method defines a function of the data structure's state and charges each operation its actual cost plus the change in potential.

The potential must be chosen so that it starts at zero, never goes negative, and rises during cheap operations by enough to pay for the expensive ones later. For a doubling array, the potential is typically twice the number of elements past the halfway mark, which reaches the array's size exactly when a copy is due.

All three methods must give the same amortised bound, since they are bookkeeping devices rather than different analyses. The aggregate method is fastest when the total is easy to sum, and the potential method is preferred when several operations interact.

The canonical example is a dynamic array that doubles when full. A single append can cost when a copy happens, but copies are rare: after a copy at size , the next occurs at size . Summing the copy costs over appends gives , so the amortised cost per append is .

The reason doubling works and adding a constant does not is that doubling makes the gaps between copies grow geometrically, while adding a fixed amount makes them constant, giving copies of average cost and a quadratic total.

7. Worked Examples

Example 1. Order these by growth rate: , , , , .

Simplify what can be simplified first. with a base-2 logarithm is exactly , so it is linear.

For , take logarithms: . Compare with , whose logarithm is , dominated by . Since exceeds , the function grows faster than .

Compare with , whose logarithm is . Dividing both logarithms by reduces the comparison to against the constant , and exceeds for any reasonably large . So the quasi-polynomial is larger.

Finally, dominates everything here, since its logarithm is by Stirling's approximation, which exceeds by a wide margin.

The order is .

The lesson is that taking logarithms is the reliable method whenever the hierarchy does not settle a comparison by inspection, because it converts exponents into products that can be compared term by term.

Example 2. Solve using the master theorem.

Identify , , and .

Compute the critical exponent: , so .

Compare against . Since grows faster than , and , we have for .

That is case 3, so check regularity: is for some ?

, so and the condition holds.

Therefore .

Example 3. Solve .

Identify , , so .

Compare against . It is smaller, which suggests case 1 — but case 1 requires to be polynomially smaller, that is for some positive .

It is not. The ratio grows more slowly than any positive power of , so no works. The master theorem does not apply.

Use a recursion tree. At level there are nodes of size , so the level's work is

Summing over from 0 to gives times the sum of , which is times the harmonic series up to .

That harmonic sum is , so .

This is the standard example of the master theorem's gap, and recognising the gap is more of the answer than the arithmetic.

Example 4. A loop runs for (i = 1; i < n; i = i * 3) containing an inner loop running for (j = 0; j < i; j++). What is the total cost?

The outer counter takes values up to , so it runs times.

The inner loop runs times for each outer value, so the total is the sum of the outer values:

This is a geometric series with ratio 3, and its sum is dominated by its last term, which is .

Precisely, the sum equals where , which is .

The total cost is , not .

The trap is multiplying the loop counts. The outer loop runs times and the inner runs up to times, which suggests — but the inner loop reaches only on the final iteration, and the geometric series is dominated by that single term.

Example 5. Prove by substitution that is .

Guess for some constant and all .

Assume it holds for : .

Substitute into the recurrence:

For this to be at most , we need , that is .

So the bound holds with , provided the base case is satisfied — and for , requires the constant to be chosen large enough, which is always permitted since may be raised.

The induction closes, so .

Note the shape of the argument. The recurrence produced an extra term that had to absorb the , and that absorption is what fixed the constant. A guess of would have failed here precisely because no such slack appears.

Example 6. A dynamic array doubles its capacity when full. Show that appends cost in total, and explain why growing by a fixed increment does not.

Under doubling, a copy occurs when the array is full, at sizes up to .

A copy at size costs operations, so the total copying cost is

because a geometric series with ratio 2 sums to less than twice its largest term.

Adding the appends themselves gives at most operations for appends, so the amortised cost per append is .

Now consider growing by a fixed increment . Copies occur at sizes , so there are copies, and the copy at size costs .

The total is .

That is for any fixed , so the amortised cost per append is rather than .

The difference is geometric versus arithmetic growth in the gaps between copies. Doubling makes each copy twice as rare as it is expensive, so the two effects cancel; a fixed increment makes copies equally frequent while they grow steadily more expensive.

Summary

Asymptotic notation describes growth, not speed, and discards constants and lower-order terms precisely because those depend on the machine rather than the algorithm.

is an upper bound, a lower bound, both, and and their strict versions. An upper bound need not be tight, and the notation describes a function rather than an algorithm, so best, average and worst case must be distinguished.

Any polynomial beats any polylogarithm and any exponential beats any polynomial. Logarithm bases are irrelevant; exponential bases are not. When the hierarchy does not settle a comparison, take logarithms.

Loop analysis counts innermost executions. A multiplying counter gives iterations, a squaring counter gives , and nested loops multiply only when independent.

A divide-and-conquer recurrence is read off the code: number of calls, subproblem size, and work outside. Recursion trees generate the guess and substitution proves it, sometimes needing a strengthened hypothesis.

The master theorem compares against : polynomially smaller gives leaf domination, equal up to logs gives a balanced tree with one extra log, and polynomially larger with regularity gives root domination.

The theorem fails when differs by a non-polynomial factor, and is the standard example, solving to by recursion tree.

Amortised analysis bounds the average over a worst-case sequence and involves no probability. Doubling a dynamic array gives amortised appends because the gaps between copies grow geometrically, while a fixed increment gives .

Key formulas & results

Everything to memorise for the exam hall, in one card. Screenshot this for revision.

The organising tool
ASYMPTOTIC NOTATION IS A CLAIM ABOUT GROWTH, NOT ABOUT SPEED. IT DISCARDS CONSTANTS AND LOWER-ORDER TERMS BECAUSE THOSE DEPEND ON THE MACHINE, NOT THE ALGORITHM.
AN n log n ALGORITHM CAN BE SLOWER THAN A QUADRATIC ONE ON EVERY INPUT YOU WILL EVER RUN. ASYMPTOTICS SAY WHICH WINS EVENTUALLY, NOT WHICH WINS TODAY.
Formal definition of O
f(n) = O(g(n)) MEANS THERE EXIST POSITIVE CONSTANTS c AND n0 WITH 0 AT MOST f(n) AT MOST c TIMES g(n), FOR ALL n AT LEAST n0.
THE CONSTANT c ABSORBS ANY MULTIPLICATIVE FACTOR AND n0 ALLOWS THE BOUND TO FAIL FOR SMALL INPUTS, WHICH IS EXACTLY WHY LOWER-ORDER TERMS ARE IRRELEVANT.
The five notations
O IS AT MOST, OMEGA IS AT LEAST, THETA IS EXACTLY, LITTLE-o IS STRICTLY LESS, AND LITTLE-OMEGA IS STRICTLY GREATER.
THETA IS BOTH O AND OMEGA SIMULTANEOUSLY, SO PROVING A TIGHT BOUND MEANS PROVING TWO INEQUALITIES RATHER THAN ONE.
Two cautions about O
AN UPPER BOUND NEED NOT BE TIGHT, AND THE NOTATION DESCRIBES A FUNCTION RATHER THAN AN ALGORITHM.
SAYING INSERTION SORT IS O(n CUBED) IS TRUE AND USELESS. AN ALGORITHM HAS DIFFERENT BOUNDS FOR BEST, AVERAGE AND WORST CASE, SO ONE MUST BE NAMED.
The growth hierarchy
1, log log n, log n, ROOT n, n, n log n, n SQUARED, n CUBED, 2 TO THE n, n FACTORIAL, n TO THE n.
MOST QUESTIONS ARE ASKING WHERE A FUNCTION SITS IN THIS LIST, SO IT IS WORTH MEMORISING RATHER THAN DERIVING.
The three comparison rules
ANY POLYNOMIAL BEATS ANY POLYLOGARITHM. ANY EXPONENTIAL BEATS ANY POLYNOMIAL. LOGARITHM BASES ARE IRRELEVANT BUT EXPONENTIAL BASES ARE NOT.
n TO THE 0.001 EVENTUALLY OVERTAKES log n TO THE 1000. 2 TO THE n AND 3 TO THE n DIFFER BY AN EXPONENTIAL FACTOR, NOT A CONSTANT.
Comparing by logarithms
WHEN THE HIERARCHY DOES NOT SETTLE A COMPARISON, TAKE LOGARITHMS OF BOTH FUNCTIONS AND COMPARE THOSE, OR APPLY L'HOPITAL TO THE RATIO.
FOR n TO THE log n AGAINST log n TO THE n, THE LOGARITHMS ARE (log n) SQUARED AGAINST n log log n, AND THE SECOND IS LARGER.
Loop counting
AN ADDITIVE COUNTER GIVES THETA(n) ITERATIONS. A MULTIPLICATIVE COUNTER GIVES THETA(log n). A SQUARING COUNTER GIVES THETA(log log n).
NESTED LOOPS MULTIPLY ONLY WHEN INDEPENDENT. AN INNER LOOP RUNNING TO THE OUTER COUNTER GIVES THE SUM 1 THROUGH n, WHICH IS THETA(n SQUARED).
Reading a recurrence
T(n) = a T(n/b) + f(n), WHERE a IS THE NUMBER OF SUBPROBLEMS, n/b THEIR SIZE, AND f(n) THE WORK OF DIVIDING AND COMBINING.
ALL THREE ARE READ DIRECTLY OFF THE CODE. EVERYTHING AFTER THAT IS SOLVING RATHER THAN MODELLING.
Substitution method
GUESS A BOUND AND PROVE IT BY INDUCTION. IT IS THE ONLY FULLY GENERAL METHOD AND THE ONLY ONE THAT PRODUCES A PROOF.
A CORRECT GUESS CAN STILL FAIL THE INDUCTION IF THE HYPOTHESIS IS TOO WEAK. STRENGTHENING IT BY SUBTRACTING A LOWER-ORDER TERM OFTEN RESCUES IT.
Recursion tree
AT LEVEL i THERE ARE a^i NODES OF SIZE n/b^i, SO THE LEVEL'S WORK IS a^i TIMES f(n/b^i). THE TREE HAS log base b OF n LEVELS AND n^(log base b of a) LEAVES.
THREE OUTCOMES ARE POSSIBLE AND THEY CORRESPOND EXACTLY TO THE THREE MASTER-THEOREM CASES: ROOT DOMINATES, LEAVES DOMINATE, OR EVERY LEVEL CONTRIBUTES EQUALLY.
The critical exponent
COMPARE f(n) AGAINST n TO THE POWER log base b OF a. THAT EXPONENT IS THE TOTAL WORK AT THE LEAVES OF THE RECURSION TREE.
EVERY MASTER-THEOREM CASE IS DECIDED BY WHETHER f IS POLYNOMIALLY SMALLER, COMPARABLE, OR POLYNOMIALLY LARGER THAN THIS QUANTITY.
Master theorem case 1
IF f(n) = O(n TO THE POWER (log base b of a, MINUS epsilon)) FOR SOME POSITIVE epsilon, THEN T(n) = THETA(n TO THE POWER log base b of a).
THIS IS THE LEAF-DOMINATED CASE: THE WORK SHRINKS GOING DOWN THE TREE SO FAST THAT THE LEAVES CARRY IT ALL.
Master theorem case 2
IF f(n) = THETA(n TO THE POWER log base b of a, TIMES log TO THE k OF n) FOR k AT LEAST 0, THEN T(n) GAINS ONE MORE LOGARITHM: THETA OF THE SAME TIMES log TO THE (k+1).
THIS IS THE BALANCED CASE: EVERY LEVEL CONTRIBUTES THE SAME, AND THE EXTRA LOGARITHM COUNTS THE LEVELS.
Master theorem case 3
IF f(n) = OMEGA(n TO THE POWER (log base b of a, PLUS epsilon)) AND THE REGULARITY CONDITION HOLDS, THEN T(n) = THETA(f(n)).
REGULARITY MEANS a TIMES f(n/b) IS AT MOST c TIMES f(n) FOR SOME c LESS THAN 1. IT HOLDS FOR EVERY POLYNOMIAL f IN PRACTICE AND IS CHECKED ONLY WHEN f IS UNUSUAL.
When the master theorem fails
IF f IS LARGER OR SMALLER THAN THE CRITICAL FUNCTION BUT NOT POLYNOMIALLY SO — BY A FACTOR OF ONLY log n, SAY — THEN NO CASE FITS.
THE STANDARD EXAMPLE IS T(n) = 2T(n/2) PLUS n OVER log n, WHICH FALLS BETWEEN CASES 1 AND 2 AND SOLVES TO THETA(n log log n) BY RECURSION TREE.
Amortised analysis
AMORTISED ANALYSIS BOUNDS THE AVERAGE COST PER OPERATION OVER A WORST-CASE SEQUENCE. IT IS NOT AVERAGE-CASE ANALYSIS.
NO PROBABILITY IS INVOLVED: THE BOUND HOLDS FOR EVERY SEQUENCE, NOT FOR A TYPICAL ONE.
The three amortised methods
AGGREGATE BOUNDS THE TOTAL AND DIVIDES. ACCOUNTING OVERCHARGES CHEAP OPERATIONS AND BANKS THE SURPLUS. POTENTIAL CHARGES ACTUAL COST PLUS THE CHANGE IN A STATE FUNCTION.
ALL THREE GIVE THE SAME BOUND, SINCE THEY ARE BOOKKEEPING DEVICES RATHER THAN DIFFERENT ANALYSES. THE POTENTIAL MUST START AT ZERO AND NEVER GO NEGATIVE.
Dynamic array doubling
COPIES OCCUR AT SIZES 1, 2, 4 AND SO ON, AND THE TOTAL COPYING COST IS LESS THAN 2n, SO THE AMORTISED COST PER APPEND IS O(1).
GROWING BY A FIXED INCREMENT k GIVES n/k COPIES SUMMING TO ABOUT n SQUARED OVER 2k, WHICH IS THETA(n) AMORTISED PER APPEND.
Why doubling works
DOUBLING MAKES THE GAPS BETWEEN COPIES GROW GEOMETRICALLY, SO EACH COPY IS TWICE AS RARE AS IT IS EXPENSIVE AND THE TWO EFFECTS CANCEL.
A FIXED INCREMENT MAKES COPIES EQUALLY FREQUENT WHILE THEY GROW STEADILY MORE EXPENSIVE, WHICH IS WHY THE TOTAL BECOMES QUADRATIC.
⚠️

Traps GATE sets — and how to dodge them

These are the exact option-traps and misreads that cost marks under negative marking.

WATCH OUT
Treating an asymptotically better algorithm as faster on all inputs
Asymptotics describe the limit as n grows without bound. A large constant can make an n log n algorithm slower than a quadratic one across every input size that will actually occur.
WATCH OUT
Quoting an O bound without saying which case it describes
The notation bounds a function, and an algorithm has separate best, average and worst-case functions. Quicksort is O(n squared) worst case and O(n log n) average, and both statements are correct.
WATCH OUT
Assuming an O bound is tight
O is an upper bound only. Every linear algorithm is also O(n squared) and O(2 to the n), so a correct O statement can still be uninformative. Theta is what asserts tightness.
WATCH OUT
Treating exponential bases as interchangeable
Logarithm bases differ by a constant factor and vanish under O, but 3 to the n divided by 2 to the n is (1.5) to the n, which grows without bound. Exponential bases must be preserved.
WATCH OUT
Multiplying loop bounds when the inner depends on the outer
A loop tripling its counter runs log n times, and an inner loop running to the counter reaches n only on the last iteration. The total is a geometric series dominated by its last term, giving Theta(n) rather than n log n.
WATCH OUT
Applying the master theorem when f differs by a logarithmic factor
Cases 1 and 3 require f to be polynomially smaller or larger, meaning by a factor of n to some positive power. A factor of log n is not polynomial, so no case applies and a recursion tree is required.
WATCH OUT
Skipping the regularity condition in case 3
Case 3 requires a f(n/b) at most c f(n) for some c below 1, which guarantees the work genuinely shrinks going down the tree. It holds for polynomial f but must be stated, and it can fail for oscillating functions.
WATCH OUT
Computing the critical exponent as a over b
The exponent is log base b of a, not a divided by b. For a = 3 and b = 4 it is about 0.792, and using 0.75 instead can flip which master case applies.
WATCH OUT
Failing an induction and abandoning a correct guess
A correct bound often fails the naive induction because the hypothesis is too weak. Subtracting a lower-order term from the hypothesis strengthens it and frequently closes the proof.
WATCH OUT
Confusing amortised with average-case analysis
Amortised analysis involves no probability and holds for every sequence of operations. Average-case analysis assumes a distribution over inputs and says nothing about an adversarial sequence.
WATCH OUT
Assuming any growth policy gives constant amortised appends
Only geometric growth does. Doubling gives a total copying cost below 2n, while growing by a fixed increment gives roughly n squared over 2k, so the amortised cost per append becomes linear.
WATCH OUT
Comparing functions by inspection when the hierarchy does not cover them
Take logarithms of both and compare. For n to the log n against log n to the n, the logarithms are (log n) squared against n log log n, and the second wins comfortably.

Exam-pattern practice

PYQ-style questions with full solutions. Work through them as a readiness check — mark yourself honestly and get your gap report at the end.

Readiness check

Are you exam-ready for Asymptotic Complexity & Recurrences?

9 problems from this chapter. Try each one, reveal the worked solution, mark yourself honestly — get your gap report at the end.

9 questions~6 min

5-minute revision

The whole chapter, distilled. Read this the night before the exam.

  • Asymptotics describe growth, not speed.
  • Constants and lower-order terms are discarded deliberately.
  • A better asymptotic can be slower in practice.
  • O is at most, Omega at least, Theta exactly.
  • Little-o and little-omega are the strict versions.
  • The definition uses two constants, c and n0.
  • An O bound need not be tight.
  • Notation bounds a function, not an algorithm.
  • Name the case: best, average or worst.
  • Any polynomial beats any polylogarithm.
  • Any exponential beats any polynomial.
  • Logarithm bases vanish under O.
  • Exponential bases do not.
  • Take logarithms when the hierarchy does not settle it.
  • An additive counter gives n iterations.
  • A multiplying counter gives log n.
  • A squaring counter gives log log n.
  • Nested loops multiply only when independent.
  • Read a recurrence off the code: calls, size, outside work.
  • Substitution guesses and proves by induction.
  • Strengthen a failing hypothesis by subtracting a term.
  • A recursion tree generates the guess.
  • Level i has a^i nodes of size n over b^i.
  • The leaves number n to the log base b of a.
  • The critical exponent is log base b of a.
  • Case 1 is leaf-dominated.
  • Case 2 is balanced and adds one logarithm.
  • Case 3 is root-dominated and needs regularity.
  • The comparison must be polynomial, not merely larger.
  • 2T(n/2) plus n over log n is the standard gap case.
  • It solves to Theta(n log log n).
  • Amortised is not average-case.
  • Aggregate, accounting and potential give the same bound.
  • Doubling gives O(1) amortised appends.
  • A fixed increment gives Theta(n) amortised.

GATE question blueprint

How this topic is asked, tier by tier — so you can prep to the pattern.

Typical weightage: Algorithms contributes roughly 8-10 of the 72 core-CS marks; complexity and recurrences supply 2-3 of those across 2-3 questions

Question styleMarks eachTypical countWhat it tests
Growth rates1~1Ordering functions and simplifying disguised forms
Notation1~1Distinguishing the five notations and their strictness
Loop analysis2~1Multiplicative counters and dependent inner bounds
Master theorem2~1Computing the critical exponent and selecting the correct case
Master theorem gap2~1Recognising non-polynomial differences and solving by recursion tree
Recursion trees2~1Uneven splits and summing level by level
Substitution method2~1Closing an induction and strengthening a weak hypothesis
Amortised analysis2~1Aggregate and accounting arguments over a worst-case sequence

Exam-hall strategy

Battle-tested tips from mentors and toppers for this topic under the sectional clock.

  1. Compute the critical exponent as log base b of a, never a divided by b.
  2. Check that the master-theorem comparison is polynomial before choosing a case.
  3. Reach for a recursion tree whenever subproblem sizes differ or the gap appears.
  4. For loop questions, check whether the inner bound depends on the outer counter.
  5. Take logarithms whenever two functions cannot be ordered by inspection.
  6. For amortised questions, bound the total over the whole sequence rather than one operation.
  7. Complexity classes and recurrence solutions are commonly set as MSQs and NATs, which carry no negative marking, so never leave one blank.
  8. For 1-mark and 2-mark MCQs, negative marking is -1/3 and -2/3, so guess only after eliminating an option.
  9. GATE gives a single freely-navigable 180-minute window, so flag a long recursion tree and return to it.

Beyond the exam

Where this skill shows up in the job you're competing for — and in life.

Choosing a sort for small inputs

Library sorts switch to insertion sort below a dozen elements precisely because the asymptotic ordering reverses under the crossover point.

Sizing a growable buffer

The doubling policy in every dynamic array implementation is a direct application of the amortised argument, and the choice of factor trades memory against copy frequency.

Predicting how an algorithm scales

Knowing that a quadratic routine takes four times as long when the input doubles is what turns a profiling measurement into a capacity forecast.

Reading a divide-and-conquer implementation

Counting the recursive calls and the combine work gives the recurrence directly, which is how a new algorithm's cost is established before any measurement.

Where else this topic is tested

Prepare once, score in every exam that asks it.

GATE DAHigh overlap — asymptotic analysis and recurrences appear with the same treatment, applied to data-processing algorithms
UGC NET Computer ScienceHigh overlap — growth-rate ordering and master-theorem application are examined as direct recall and short computation
ISRO / BARC / DRDO computer science papersVery high overlap — loop counting, recurrence solving and complexity ordering are recurring MCQ topics

Questions aspirants ask

Pulled from the Q&A community and mentor sessions.

Whenever the input sizes that matter fall below the crossover point where the asymptotically better algorithm actually overtakes. The notation makes a claim about the limit as n grows without bound, and nothing about any particular n. An algorithm running in 1000 n log n steps is asymptotically better than one running in n squared over 2, but the second is faster until n exceeds roughly 4000, and for many real workloads that is the entire range of interest. This is why practical sorting libraries switch to insertion sort for small subarrays even though it is quadratic: its constant is tiny and the crossover is around a dozen elements. Three related cautions are worth carrying. Memory behaviour is invisible to the notation, so an algorithm with worse asymptotics but sequential access can beat one with better asymptotics and scattered access, which is exactly why heapsort often loses to quicksort. Amortised bounds hide worst-case latency, so a structure with O(1) amortised operations may occasionally block for O(n), which matters in real-time systems. And the notation says nothing about which case is being described, so quoting a worst-case bound for an algorithm whose average case is far better, as with quicksort, gives a misleading picture. The correct use is to treat asymptotics as the first filter and measurement as the decision.

Compute the critical function n to the power log base b of a, then ask how f compares to it — and insist that the comparison be polynomial. If f is smaller by at least a factor of n to some positive power, case 1 applies and the answer is the critical function itself, because the leaves dominate. If f equals the critical function times log to some non-negative power k, case 2 applies and the answer gains exactly one more logarithm, because every level contributes equally and there are log n levels. If f is larger by at least a factor of n to some positive power, case 3 applies and the answer is f itself, because the root dominates — subject to the regularity condition that a f(n/b) is at most c f(n) for some c below one. Two things go wrong most often. The first is computing the critical exponent as a divided by b rather than log base b of a; for a = 3 and b = 4 those give 0.75 and 0.792, which can flip the case. The second is accepting a merely-larger or merely-smaller f when the difference is only logarithmic. A factor of log n is not polynomial, so neither case 1 nor case 3 applies, and the recurrence falls into a genuine gap. Recognising the gap is worth as much as solving it, and the resolution is always a recursion tree.

Because the tree makes no structural assumptions, while the theorem requires a very specific shape. The master theorem applies only to recurrences of the form a T(n over b) plus f(n), meaning every subproblem must have exactly the same size and that size must be the original divided by a constant. It also requires f to compare polynomially with the critical function. Any recurrence violating either requirement is outside its scope. A recursion tree simply draws what the recursion does. Each node is a subproblem, its children are the recursive calls it makes, and the node is labelled with the work done outside those calls. Summing the labels level by level and then across levels gives the total, with no assumptions about uniformity at all. That is why it handles uneven splits such as T(n/3) plus T(2n/3) plus n, where the subproblems differ in size but their sizes always sum to n, giving n work per level and Theta(n log n) overall. It also handles the logarithmic-gap case, where each level contributes n over (log n minus i) and the sum becomes a harmonic series giving Theta(n log log n). The one weakness is rigour: a tree produces a convincing value rather than a proof, and the value should be confirmed by substitution if a proof is required. In exam conditions the tree is almost always sufficient, and the substitution step is asked for explicitly when it is wanted.

Amortised analysis involves no probability at all, and that is the whole distinction. An average-case bound assumes a probability distribution over inputs — usually that all permutations are equally likely — and reports the expected cost under that assumption. If the real inputs are drawn from a different distribution, or if an adversary chooses them, the bound says nothing. Quicksort's O(n log n) average case is exactly this kind of claim, and an adversary who knows the pivot rule can force the quadratic worst case on every run. An amortised bound makes a worst-case guarantee about a sequence. It says that any sequence of n operations, chosen however maliciously, costs at most a certain total, so the average per operation across that sequence is bounded. The dynamic array is the standard example: no adversary can make n appends cost more than about 3n operations, because the copies are structurally forced to be geometrically rare. The bound is unconditional. Two refinements matter. An amortised bound says nothing about any individual operation, so a structure with O(1) amortised cost can still block for O(n) on one call, which is why real-time systems sometimes prefer a worse but uniform bound. And the three methods — aggregate, accounting and potential — are bookkeeping alternatives that must produce the same answer, so the choice among them is about convenience rather than power.

Because doubling makes the copies geometrically rare at exactly the rate they become expensive, and the two effects cancel, while a fixed increment lets the cost rise while the frequency stays constant. Under doubling, a copy occurs when the array is full, so copies happen at sizes 1, 2, 4, 8 and so on. The copy at size k costs k operations, and the total across n appends is 1 plus 2 plus 4 up to n, a geometric series summing to less than 2n. Spread over n appends, that is under two extra operations each, so the amortised cost is O(1). Under a fixed increment k, copies occur at sizes k, 2k, 3k and so on, giving n over k copies. The copy at size ik costs ik, so the total is k times the sum of 1 through n over k, which is approximately n squared over 2k. Spread over n appends, that is n over 2k operations each — linear in n, not constant. Choosing a larger k improves the constant but never the asymptotic behaviour, because the number of copies still grows linearly while their individual cost also grows linearly. The general principle is that any growth factor strictly greater than 1 gives constant amortised cost, since the sizes then form a geometric series. Growth factors of 1.5 or 2 are both used in practice, with 1.5 wasting less memory and 2 copying slightly less often.
Header Logo