Big O and Big Omega Notations

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Big O and Big Omega Notations

Discusses the Big O notation with examples

In the previous section, we defined Θ notation. In this section, we'll discuss


big O and big Ω notations. The reader would notice the use of the adjective
"big" with these notations and rightly suspect that there exist
complementary small o and small ω notations, which we'll discuss in the
next lesson.

Big O

Big O is expressed as O(g(n)) and is pronounced as "big oh of g of n". We


observed that Θ provides both an asymptotically upper and lower tight
bound. Big O only provides an asymptotic upper bound which may not
necessarily be a tight bound.

Big O is the most commonly talked-about notation when discussing


algorithms in industry settings or in interviews. You won't see Θ or other
notations being discussed, and for good reason too. Generally, if we are
guaranteed that an algorithm will perform no worse than a certain
threshold, and that threshold is acceptable for the problem at hand, then
knowing its best-case performance or finding a very tight upper bound may
not be productive.

Formal De nition

Similar to Θ we define O(g(n)) as a set of functions and a function f(n)


can be a member of this set if it satisfies the following conditions:

0 ≤ f (n) ≤ cg(n)

(/learn) constant and the inequality holds after n crosses a


where c is a positive
positive threshold n0
positive threshold n0

Explanation

if f(n) = Θ (g(n)) then it also implies that f(n) = O (g(n))

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.

As a general rule of thumb, for an expression consisting of polynomials the


expression/function is O(the highest polynomial degree in the expression).

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

As before, Ω(g(n)) is a set of functions and any function f(n) that


satisfies the below constraints belongs to this set and f(n) is said to be
big omega of g(n).

0 ≤ g(n) ≤ f (n)

where c is a positive constant and the above inequality holds af


ter n crosses a positive threshold n0

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).

Big Ω is not necessarily a tight lower bound.

If f(n) Θ(g(n)) then it also implies f(n) Ω(g(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)).

1(n2 + 2) < 2n2 − 1 < 2(n2 + 2)

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

Big O isn’t necessarily a tight bound, whereas Θ is a tight


bound so we cannot definitely say that f(n) is O(n3) given
the information we have.

(/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

If f(n) is Θ(g(n)) then it implies that f(n) is O(g(n)) and


Ω(g(n)). The converse is also true, that is if f(n) is O(g(n)) and
Ω(g(n)) then it must be Θ(g(n)).

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)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy