1. What is Notation?
Notation is a symbolic way of writing mathematical expressions.
Instead of writing:
“The sum of one and two”
We write:
![]()
This symbolic representation (such as
,
,
,
,
, etc.) is called mathematical notation.
2. What is Big-O Notation?
Big-O notation is a way to describe how fast a function grows as its input size increases. It’s written as:
![]()
Where
is an expression like
,
,
, etc.
3. Formal Definition
A function
is in
if there are constants
and
such that:
for all ![]()
This means:
grows no faster than
times some constant.
4. Big-O is a Set
Think of
as a set of functions. For example:
- If
, then
contains:
Any function that doesn’t grow faster than
(up to constant factors) is part of this set.
We write:
![]()
or
![]()
or
![]()
5. Examples
| Function | Big-O Notation |
6. Comparing Two Functions
Given:
We know:
grows much faster than 
Hence:
7. Constants Don’t Matter
Example:
→ 
→ 
Although
grows slower, Big-O does not show this since both are linear.
8. Why Ignore Constants?
We assume each operation takes 1 unit time (abstract model), ignoring machine-level details.
That’s why
and
are both
.
We’re interested in how the function behaves as
.
9. Multiple Input Parameters
An algorithm may depend on more than one input:
If
is the size of list A, and
is the size of list B, then:
![]()
10. Big-O Arithmetic Rules
a. Multiply by constant:
![]()
b. Same order sum:
![]()
c. Different order sum:
If
grows faster than
, then:
![]()
d. Multiplication:
![]()
11. Using Big-O in Real Code
Example:
def foo(arr):
for x in arr: # O(n)
print(x)
arr.sort() # O(n log n)
Overall complexity:
![]()
12. Growth Orders and Names
| Big-O Notation | Name | Performance |
| Constant | Excellent | |
| Logarithmic | Excellent | |
| Linear | Good | |
| Linearithmic | Acceptable | |
| Quadratic | Poor | |
| Exponential | Bad | |
| Factorial | Very Bad |
If your algorithm is worse than
, you should try optimizing it.
