0% found this document useful (0 votes)
20 views

L1-Asymtotic Notation

Uploaded by

manju
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

L1-Asymtotic Notation

Uploaded by

manju
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 31

ASYMPTOTIC NOTATIONS

ASYMPTOTIC PERFORMANCE

⚫Suppose we are considering two algorithms, A and B,


for solving a given problem.
⚫Running times of each of the algorithms are T A(n) and
TB(n) respectively, where n is a measure of the problem
size.

⚫Which is better Algorithm:


🞆If we know the problem size n in advance and then
if TA(n)< TB(n) conclude that algorithm A is
better than Algorithm B.
🞆Unfortunately, we usually don't know the problem
size beforehand.
ASYMPTOTIC PERFORMANCE
🞆 Asymptotic performance: How does an Algorithm
behave as the problem (input) size gets very large?
🞆Running time
🞆Memory/storage requirements
ALGORITHMS WITH SAME
COMPLEXITY

•Represent Complexities of both algorithms in the form of


function.

•For large value of n (input size ) two algorithms have


same complexity, if the functions representing the number
of operations have same rate of growth.
ASYMPTOTIC NOTATION
• Fortunately, there are asymptotic notations which
allow us to characterize the main factors affecting
an algorithm’s running time without going into
detail
• A good notation for large inputs.
• The notations describe different rate-of-growth
relations between the defining function and the
defined set of functions.
🞆 Big-Oh O(.) 🞆 Little-Oh o(.)

🞆 Big-Omega Ω(.) 🞆 Little-Omega ω(.)


🞆 Big-Theta Θ(.)
ASYMPTOTIC UPPER BOUND-BIG OH

Consider a function f(n) which is non-negative for all


integers . Consider another function g(n) also.

We say that ``f(n) is big oh g(n),'' which we


write f(n)=O(g(n)), if there exists an integer n0 and a
constant c>0 such that for all integers

0 ≤ f(n) ≤ c .g(n) for all n ≥ n0


ASYMPTOTIC UPPER BOUND-BIG OH

Let f(n) and g(n) represents complexities of


two algorithms.
f(n) is said to be in the family of g(n) iff
0 ≤ f(n) ≤ c .g(n) for all n ≥ n0
BIG O NOTATION
Example
If f(n) = 2n2
g(n) is O(n3 )

Que: Show that f(n) is Big Oh g(n)


Ans: to prove this we have to show that 0
≤ f(n) ≤ c g(n)
for all n ≥ n0
If we can find positive constants c and n0
then we can say that f(n) is big oh g(n)
BIG O NOTATION

🞆 Example 1
If f(n) = 2n2 , g(n) is O(n3)
f(n) ≤ c g(n)
🞆 2n2 ≤ cn3 ⇒ 2 ≤ cn ⇒ c = 1 and n0= 2
🞆 So, for c=1 and for all n ≥ 2, f(n) is big oh g(n)

🞆 There is no unique set of values for no and c in


proving the asymptotic bounds but for whatever
value of no you take, it should satisfy for all n > no
🞆 Or
🞆 For c=2 and no = 4 also, f(n) is big oh g(n)
BIG O NOTATION

🞆 Example 2
If f(n) = 8n+128, g(n) is O(n2)
To prove f(n) is big oh g(n) we have to prove that
f(n) ≤ c g(n) for all n ≥ n0 and constant c
Lets take c=1

🞆 Since (n+8)>0 for all values of n ≥ 0 , so for n0=16


🞆 Above rule is satisfied.
🞆 So, for c=1 and for all n ≥ 16, f(n) is big oh g(n)
BIG-O NOTATION

When determining the order of a function f(x), always


try to pick the smallest g(x) possible.

If f(x) is Ο(g(x)) and g(x) is Ο(f(x)), then f(x) and g(x)


are of the same order.

In practice, all big-O results are obtained for functions


that are positive for all values of x.
ASYMPTOTIC LOWER BOUND: Ω-
NOTATION

🞆 Big O is asymptotic upper bound


🞆 Ω-notation is asymptotic lower bound
Ω-NOTATION
🞆 A family of functions we say ``f(n) is omega g(n),''
iff

{ f(n) : there exist positive constants c and n o such that


0 ≤ c g(n) ≤ f(n) for all n≥ n0 }
Ω-NOTATION
Example:
For any two functions f(n) and g(n) we have
f(n) = 5n2 -64n+256 and g(n) = Ω(n2)

so, f(n) = Ω(g(n) if and only if c. g(n) ≤ f(n)

Sol: in order to show this we need to find an


integer n0 and a constant c>0 such that for all
integers n≥ n0 f(n) ≥ cn2
Ω-NOTATION
Example:
For any two functions f(n) and g(n) we have
f(n) = 5n2 -64n+256 and g(n) = Ω(n2)
suppose we choose c=1, then

So here (n-8)2 Is always positive for all n ≥ 0 so n0


=0
Hence for c=1 and n0 =0 ``f(n) is omega g(n),''
Θ- NOTATION DEFINITION

Θ( g(n) ) denotes a family of functions.

``f(n) is Theta g(n),'' if we can find constants c1, c2,


and n0 such that

0 ≤ c1 g(n) ≤ f(n) ≤ c2 g(n)


for all n ≥ n0
For any two functions f(n) and g(n) we have
f(n) = Θ(g(n))
if and only if
f(n) = O(g(n)) and f(n) = Ω(g(n))
ASYMPTOTIC TIGHT BOUND
🞆 This is said to asymptotic tight
bound.

🞆 For reasonably large values of


n, the function f(n) is within
the range of constant multiples
of g(n)

f(n) is bounded below as well


as above.
RELATIONS BETWEEN NOTAIONS
Θ- NOTATION
🞆 Example
If f(n) = 7n2 – 54n +3

g(n) is Θ (n2 )

Que: Show that f(n) is Theta g(n).


Ans: If f(n) is also having the same running
time as g(n) then prove following rule: 0
≤ c1 g(n) ≤ f(n) ≤ c2 g(n)
for all n ≥ n0
Now find c1, c2 and n0
We want c1, c2 and n0 such
7n2 – 54n +3 that
c1n2≤ 7n2 – 54n +3 ≤ c2n2
for all n ≥ n0

Select c1 < 7 and 7< c2

Say c1 = 5 and c2 = 9

To get 5n2≤ 7n2 – 54n +3,


n must be bigger than 27.

7n2 – 54n +3 ≤ 9n2 is true for all n.

Thus c1 = 5, c2 = 9 and n0 = 28
TAKE ANOTHER EXAMPLE

If f(n) = 7n3 – 54n2 + 10n + 3


Can g(n) be n2 ?

NO
c2n2 cannot be larger than n3 for large n.
Thus you cannot find c1, c2 and n0
Thus f(n) ≠ Θ (n2 )
LITTLE O-NOTATION

o(g(n) ={ f(n):
for any positive constant c > 0 there
exists a constant n0 > 0 such that
0 ≤ f(n) < cg(n) for all n ≥ n0 }

Limit f/g → 0
LITTLE Ω-NOTATION

ω(g(n) ={ f(n):
for any positive constant c > 0 there
exists a constant n0 > 0 such that
0 ≤ cg(n) < f(n) for all n ≥ n0 }

Limit g/f → 0
NAMES OF MOST COMMON
BIG OH FUNCTIONS
🞆 Constant O(1)
🞆 Logarithmic O(log n)
🞆 Linear O(n)
🞆 Quadratic O(n2)
🞆 Polynomial O(nk) k is a constant

🞆 Exponential O(2n)
🞆 Exponential O(an) a is a constant and a
>1
THEOREM
🞆 R1: If d(n) is O(f(n)), then ad(n) is O(f(n),
a>0

🞆 R2: If d(n) is O(f(n)) and e(n) is O(g(n)),


then d(n)+e(n) is O(f(n)+g(n))

🞆 R3: If d(n) is O(f(n)) and e(n) is O(g(n)),


then d(n)e(n) is O(f(n)g(n))

🞆 R4: If d(n) is O(f(n)) and f(n) is O(g(n)),


then d(n) is O(g(n))
THEOREM

🞆 R5: If f(n) = a0 + a1n + … + adnd, d and ak


are constants, then f(n) O(nd)

🞆 R6: nx is O(an) for any fixed x > 0 and a > 1

🞆 R7: log nx is O(log n) for any fixed x > 0

🞆 R8: log xn is O(ny) for any fixed constants x


> 0 and y > 0
SOME HELPFUL MATHEMATICS
🞆 Constant Series: For integers a and b, a ≤ b,

🞆 Linear Series (Arithmetic Series): For n ≥ 0,

🞆 Quadratic Series: For n ≥ 0,


SOME HELPFUL MATHEMATICS
🞆 Cubic Series: For n ≥ 0,

🞆 Geometric Series: For real x ≠ 1,

For |x| < 1,


SOME HELPFUL
MATHEMATICS
🞆 Cubic Series: For n ≥ 0,

🞆 Geometric Series: For real x ≠ 1,

For |x| < 1,

You might also like