Big O and Big Omega Notations
Big O and Big Omega Notations
Big O and Big Omega Notations
Big O
Formal De nition
0 ≤ f (n) ≤ cg(n)
Explanation
The notation means that the function f(n) is bounded by above to within
a constant factor of g(n).
Note that the inequality requires f(n) to be greater than 0 after n crosses
n0.
The set O(g(n)) may also contain other functions also that satisfy the
inequality. There could be several values of c that can be used to satisfy
the inequality.
Insertion Sort
Previously, we came up with the following f(n) for the insertion sort
algorithm
n(n − 1)
f (n) = [2 ∗ (n + 1) + 2n] + [2n + 7[ ]]
2
Now we can attempt to find the O(g(n)) for this expression. As a general rule
of thumb, when working with big O we can drop the lower order terms and
n(n-1)
concentrate only on the higher order terms. The term ⁄2 is the highest
order term, since it involves a square of n. The above expression is thus
quadratic, and we can ignore all the constants and linear terms. Thus a tight
bound on the expression would be O(n2). We can prove it below:
(/learn)
n(n − 1)
≤ cn2
2
let c = 10 and n0 = 10
You can always pick a different set of constants as long as it satisfies the
inequality for all n > n0.
Big Ω
The complementary notation for big O is the big omega notation. The big
omega notation provides an asymptotic lower bound and is expressed as
Ω(g(n)).
Formal De nition
0 ≤ g(n) ≤ f (n)
Explanation
(/learn)
Notice that similar to big O, the definition mandates we only consider
ot ce t at s a to b g O, t e de to a dates e o y co s de
positive values for f(n).
Relation to Θ
One can see that if a function f(n) is Θ(g(n)) then it follows that f(n) must be
O(g(n)) and Ω(g(n)). In the previous lesson we proved that f(n) = 2n2-1 was
Θ((n2)). We can simply consider the right and left handsides of the following
inequality in isolation to prove that f(n) is also O(g(n)) and Ω(g(n)).
Quiz
1
You are told that a function f(n) is O(n3), does it also imply that the f(n)
is Θ(n3) ?
Your Answer
A) No
Explanation
(/learn)
B) Yes
2
You are told that a function f(n) is O(n) and also Ω(n), does it also imply
that the f(n) is Θ(n) ?
A) No
Your Answer
B) Yes
Explanation
SUMMARY
Correct 2
Incorrect 0
(/learn)
Awesome! you got all 2 correct!
Retake Quiz
← Back Next →
(/courses/big- (/courses/big-
MARK AS COMPLETED
o- o-
notation- notation-
for- for-
interviews- interviews-
Theta Notation Small omega and Small o Notations
and- and-
beyond/B8rPjvpO20N) beyond/gxMKl3W1lM9)
Ask a Question
Report
(https://discuss.educative.io/c/big-o-for-coding-interviews-and-beyond-c-h-
an Issue
afzal/formal-analysis-tools-big-o-and-big-omega-notations)