Asymptotic notation
The notations O, Omega, Theta, little-o and little-omega with their exact definitions, the limit test, the properties that make them usable, the hierarchy of growth rates from constants to factorials, logarithm and exponent facts, Stirling's approximation and the standard sums, with the usual mistakes.
Why it exists
How fast is an algorithm? Counting seconds depends on the machine, the language and the input; counting exact operations depends on tiny details of the code. What matters when the input grows is how the cost grows: does doubling double the work, quadruple it, or square it? Asymptotic notation keeps exactly that and throws away constant factors and lower-order terms, so that algorithms can be compared independently of the machine. It is the vocabulary of every later page.
Prerequisites
None. This is a starting point.
None. You should be comfortable with logarithms, powers and limits at school level.
Precise definitions
All functions are from the natural numbers to the non-negative reals (running times). The statements concern large .
Big-O (upper bound). if there are constants and such that
Big-Omega (lower bound). if there are and with for all .
Big-Theta (tight bound). if there are and with for all . Equivalently and .
Little-o and little-omega (strict). if for every there is with for ( grows strictly slower than ). if for every eventually .
The limit test. If exists, then
| meaning | |
|---|---|
| (so also , not ) | |
| (so also , not ) |
When the limit does not exist, use the definitions. L'Hopital's rule is the usual tool for the limit.
Reading the notation. stands for a set of functions; "" really means . states an upper bound, it does not say the bound is tight: is true. In an equation such as the stands for some function in that set. Saying that the worst case time is and saying that an algorithm is is a statement about an upper bound on the function "worst-case time", and it is a separate question whether it is best case, worst case or average case.
Properties.
- Reflexivity: . Transitivity: , , , , are each transitive.
- Symmetry: iff . Transpose symmetry: iff ; iff .
- Sums: . So .
- Products: if and then ; constants do not matter: for .
- Polynomials: a polynomial of degree with positive leading coefficient is , and for constants .
- Not every pair is comparable: and are neither nor of each other. For the functions in this course (built from powers, logarithms, exponentials, factorials) one is always asymptotically below, equal to, or above the other.
The hierarchy of growth rates (each is of the next):
Any positive power of beats any power of ; any exponential () beats any polynomial; beats every and is beaten by . Between polynomial and exponential lie functions such as (super-polynomial but ).
Logarithm and exponent facts. The base of a logarithm does not matter asymptotically: . But the base of an exponential does: , and , while . (so and ); ; .
Stirling's approximation: , which gives .
Standard sums (used constantly when counting loop iterations):
| Sum | Order |
|---|---|
| for a constant | |
| (a geometric series with ratio above 1 is dominated by its last term) | |
| (ratio below 1: dominated by the first term) | |
How it works
The table evaluates the standard functions for doubling from 1 to 64. The point of the notation is visible: for small the order means little (at the functions and are equal and is larger), but once passes a few tens the exponential and the factorial leave every polynomial behind: has 20 digits, has 90, and .
Growth of the standard functions: start
Computed by a script, not typed| n | log2 n | n | n log2 n | n^2 | n^3 | 2^n | n! |
|---|---|---|---|---|---|---|---|
| 1 | |||||||
| 2 | |||||||
| 4 | |||||||
| 8 | |||||||
| 16 | |||||||
| 32 | |||||||
| 64 |
Step 0
Compare the standard growth rates by evaluating them for n doubling from 1 to 64. Watch which column overtakes which.
Practical consequence: if an algorithm takes simple operations per second, an input of size is fine for (about operations) and for (, about ten seconds), hopeless for and unthinkable for . GATE questions ask you to rank functions and to decide which bound is correct.
Worked examples
EX 1Prove a Theta bound with constants
EasyShow . Lower bound: for all , so . Upper bound: for we have and , so , giving with . (The constant 15 is the smallest integer that works from , since at the value is exactly 15.) By the limit test, , a positive constant: .
EX 2Decide with the limit test
Easy(a) versus : , so . (b) versus : the ratio tends to 0: , however large the constant 100 looks; constants never change the order. (c) versus : ratio , a constant: . (d) versus : (every positive power of beats every power of ). (e) versus : . All were confirmed by symbolic limits.
EX 3Exponentials are subtle
Medium, so is true. But and : , so is false. In the same way (a constant shift does not matter in a polynomial) and . And , although for (at the value first exceeds ): the notation says nothing about small .
EX 4Factorials and logarithms of factorials
Mediumversus : , because from on every new factor of is at least 4 while every new factor of is 2, so the ratio at least doubles at each step. versus : (the ratio is about ). : the upper bound is immediate (, so ); the lower bound comes from keeping the largest factors, each at least , giving . So although : the logarithm hides the difference. This fact explains the lower bound for comparison sorting ( outcomes need comparisons).
EX 5Rank these functions
GATE levelArrange in increasing order of growth: , , , , , , , . Simplify first: and ; , a super-polynomial function that grows slower than . Then compare in the hierarchy:
where each term is of the next (checked pairwise with symbolic limits). A trap here is to put above : and , so it is below.
Cheat box
Cheat box
- : eventually. : . : both. , : strict (every ). Limit of : 0 gives , positive constant gives , infinity gives .
- Drop constants and lower-order terms: . Polynomial of degree is .
- Order: .
- Log base does not matter; exponential base does: but .
- ; ; .
- , , geometric ratio above 1: last term dominates.
- is an upper bound only: is true.
Traps and GATE patterns
Connections
Builds on
No prerequisites.
Across subjects
The notation is applied to loops and recursions in analysing loops, time and space and in solving recurrences, where the Master theorem compares with by exactly the tests above. It underlies the comparison of every algorithm in the later pages (sorting, searching, graph algorithms). The limit test is the one of calculus (limits).
PYQs
12 previous year questions from your book. I re-solved each one myself (11 by running or simulating, 1 by reasoning only); the book's key is shown next to my answer. All PYQs
Consider the following functions, where n is a positive integer. n1/3 , logn , log(n!) , 2logn Which one of the following options lists the functions in increasing order of asymptotic growth rate? Note: Assume the base of log to be 2.
- (a)logn , n1/3 , 2logn , log(n!)
- (b)n1/3 , logn , log(n!) , 2logn
- (c)logn , n1/3 , log(n!) , 2logn
- (d)2logn , n1/3 , logn , log(n!)
Let f and g be functions of natural numbers given by f(n)=n and g(n)=n2. Which of the following statements is/are TRUE?
- (a)f ∈ O(g)
- (b)f ∈ ω(g)
- (c)f ∈ o(g)
- (d)f ∈ θ(g)
Which one of the following statements is TRUE for all positive functions f(n)?
- (a)f(n2) = θ(f(n)2), when f(n) is a polynomial
- (b)f(n2)=o(f(n)2)
- (c)f(n2) = O(f(n)2), when f(n) is an exponential function
- (d)f(n2)= Ω (f(n)2) which one of the following options is correct?
- (a)T(n) = θ((log n) 5/2)
- (b)T(n) = θ(n)
- (c)T(n) = θ(nlog n)
- (d)T(n) = θ(n 5/2) ALGORITHMS
Consider the following three functions. f1 = 10n f2 = n logn f3 = n✓n Which one of the following options arranges the function in the increasing order of asymptotic growth rate?
- (a)f2, f1, f3
- (b)f3, f2, f1
- (c)f2, f3, f1
- (d)f1, f2, f3
Consider the following functions from positives integers to real numbers 10, √n, n, log2n, 100/n. The CORRECT arrangement of the above functions in increasing order of asymptotic complexity is:
- (a)log2n, 100/n, 10, √n, n
- (b)100/n, 10, log2n, √n, n
- (c)10, 100/n , √n, log2 n, n
- (d)100/n, log2n, 10 , √n, n
Let f(n) = n and g(n) = n (1 +sin n)
, where n is a
positive integer. Which of the following statements
is/are correct?
T(n) = {
2,
if 0 < n ≤ 2
I. f(n) = O(g(n))
Then T(n) in terms of θ notation is- (a)θ(log logn)
- (b)θ(log n)
- (c)θ(√n)
- (d)θ(n) II. f(n) = Ω(g(n))
- (a)Only I
- (b)Only II
- (c)Both I and II
- (d)Neither I nor II ALGORITHMS Check Out Our Gate Courses & Secure Your Dream Rank !
Consider the equality X =∑i=0 n i3 following choices for X: I. Θ(n4) II. Θ(n5) III. O(n5) IV. Ω(n3)
Which of the given options provides the increasing order of asymptotic complexity of functions f 1 , f 2 , f 3 and f 4 ? f1(n)=2n , f2(n)=n3/2, f3(n)=nlog2n , f4(n)=nlog n
- (a)f3, f2, f4, f1
- (b)f3, f2, f1, f4
- (c)f2, f3, f1, f4
- (d)f2, f3, f4, f1
Consider the following functions: f(n) = 2n g(n) = n! h(n) = nlogn Which of the following statements about the asymptotic behaviour of f(n), g(n), and h(n) is true?
- (a)f(n) = O(g(n)); g(n) = O(h(n))
- (b)f(n) = Ω(g(n)); g(n) = O(h(n))
- (c)g(n) = O(f(n)); h(n) = O(f(n))
- (d)h(n) = O(f(n)); g(n) = Ω(f(n))
Arrange the following functions in increasing asymptotic order: a. n1/3 b. en c. n7/4 d. nlog9n e. 1.0000001n
- (a)a, d, c, e, b
- (b)d, a, c, e, b
- (c)a, c, d, e, b
- (d)a, c, d, b, e
Match the algorithms with their time complexities: Algorithm Time complexity P Towers of Hanoi with n disks i Θ(n2 ) Q Binary search given n sorted numbers ii Θ(nlog n) R Heap sort given n numbers at the worst case iii Θ(2n ) S Addition of two n × n matrices iv Θ(logn) ALGORITHMS Check Out Our Gate Courses & Secure Your Dream Rank !
- (a)P-(iii), Q-(iv), R-(i), S-(ii)
- (b)P-(iv), Q-(iii), R-(i), S-(ii)
- (c)P-(iii), Q-(iv), R-(ii), S-(i)
- (d)P-(iv), Q-(iii), R-(ii), S-(i)
Two alternative packages A and B are available for processing a database having 10k records. Package A requires 0.0001n2 time units and package B requires 10n log10 n time units to process n records. What is the smallest value of k for which package B will be preferred over A?
- (a)12
- (b)10
- (c)6
- (d)5
Self-check
Question 1
Is ? Is ?
Show answerHide
Yes to the first (), no to the second ().
Question 2
Which is larger asymptotically, or ?
Show answerHide
. Since and , we have .
Question 3
Give the order of .
Show answerHide
: the sum is at most , and the largest terms are each at least .
Question 4
If and , what can be said about and ?
Show answerHide
and .
Revision card
One-screen revision
- (upper), (lower), (both), , (strict); limit of : , constant, .
- Drop constants and lower-order terms; log base is irrelevant, exponential base is not.
- .
- , , .
References
- ·Cormen, Leiserson, Rivest, Stein, Introduction to Algorithms (3rd edition), Chapter 3 Growth of Functions (asymptotic notation, standard notations and common functions)
- ·Kleinberg and Tardos, Algorithm Design, Chapter 2 Basics of Algorithm Analysis (2.2 asymptotic order of growth)
Verification
Every relation between two functions on this page (22 of them, including the ordered list of the example) was decided by a symbolic limit of f(n) / g(n) computed by sympy, an independent method (scripts/enum-checks/algo_analysis.py). The explicit constants 3 and 15 of the first example were checked for every n from 1 to 4999 and shown to be the smallest integers that work from n = 1. Stirling's approximation, the harmonic sum and the standard sums were checked numerically. The table of growth values is computed exactly by script (scripts/gen-algo-traces.py). Textbook chapter references are from memory. SECOND PASS (2026-11-02, done by the assistant, not a human check): every Self-check question was solved before the printed answer was read and all agreed; the definitions, worked examples, cheat box and traps were read claim by claim and the numbers re-derived by hand or by a small script (loop counts, recurrences, merge and quicksort counts and averages, hash probes and load-factor formulas, DP tables, MST and shortest-path runs, Floyd matrices); long C programs were not re-read line by line (they are compiled and compared by npm run verify:c, and their printed outputs were checked against the prose); tables and animations are machine output and were read, not re-run; One wrong number was fixed: 64! has 90 digits, not 89 (also in the generator scripts/gen-algo-traces.py and the table-growth trace), and a runtime remark was made exact (about ten seconds). Status raised to self-checked; verified needs a textbook or human check.
last verified: never
My notes (saved in this browser)