Docsity

Asymptotic Notation and Analysis in Algorithm Complexity, Slides of Data Structures and Algorithms

Partial preview of the text

Download Asymptotic Notation and Analysis in Algorithm Complexity and more Slides Data Structures and Algorithms in PDF only on Docsity!

Data Structures and Algorithms

CSE- 101

  • asymp - 1 Comp

Asymptotic Notation

Asymptotic Analysis

 Asymptotic analysis is a method of

describing limiting behavior.

 Suppose that we are interested in the properties

of a function f ( n ) as n becomes very large.

 f ( n ) = n

2

+ 3 n ,

 As n becomes very large, the term 3 n becomes

insignificant compared to n

2

Asymptotic Complexity

 Running time of an algorithm as a function of

input size n for large n.

 Expressed using only the highest-order term in

the expression for the exact running time.

 Instead of exact running time, say Q( n

2

 Describes behavior of function in the limit.

 Written using Asymptotic Notation.

Asymptotic Notation

 Q , O , W , o , w
 Defined for functions over the natural numbers.
 Ex: f ( n ) = Q( n

2

 Describes how f ( n ) grows in comparison to n

2

 Define a set of functions; in practice used to compare
two function sizes.
 The notations describe different rate-of-growth
relations between the defining function and the
defined set of functions.

Q-notation

Q ( g ( n )) = { f ( n ) :

positive constants c 1 , c 2 , and n 0, such thatnn 0 , we have 0c 1 g ( n )f ( n )c 2 g ( n )

For function g ( n ), we define Q( g ( n )), big-Theta of n , as the set: Technically, f ( n )  Q( g ( n )). Older usage, f ( n ) = Q( g ( n )). f ( n ) and g ( n ) are nonnegative, for large n****.

Example

 10 n

2

  • 3 n = Q( n 2

 What constants for n

0

, c

1

, and c

2

will work?

 Make c

1

a little smaller than the leading

coefficient, and c

2

a little bigger.

 To compare orders of growth, look at the

leading term.

 Exercise: Prove that n

2

/2- 3 n = Q( n

2

Q ( g ( n )) = { f ( n ) :  positive constants c

1 , c 2 , and n 0

such thatnn 0 , 0c 1 g ( n )f ( n )c 2

g ( n )}

O - notation

O ( g ( n )) = { f ( n ) :

positive constants c and n 0, such thatnn 0 ,

we have 0  f ( n )  c g ( n ) }

For function g ( n ), we define O ( g ( n )), big-O of n , as the set: g ( n ) is an asymptotic upper bound for f ( n ). Intuitively : Set of all functions whose rate of growth is the same as or lower than that of g ( n ). f ( n ) = Q ( g ( n ))f ( n ) = O ( g ( n )). Q ( g ( n ))O ( g ( n )).

Examples

 Any linear function an + b is in O ( n

2

). How?

 Show that 3 n

3

= O ( n

4

) for appropriate c and n

0

O ( g ( n )) = { f ( n ) :  positive constants c and n

0

such that  n  n

0

, we have 0  f ( n )  c g ( n ) }

Example

 n = W(lg n ). Choose c and n

0

W( g ( n )) = { f ( n ) :  positive constants c and n

0

, such
that  n  n

0

, we have 0  c g ( n )  f ( n )}

Relations Between Q, O, W

o - notation

f ( n ) becomes insignificant relative to g ( n ) as n
approaches infinity:

lim [ f ( n ) / g ( n )] = 0 n 

g ( n ) is an upper bound for f ( n ) that is not
asymptotically tight.
Observe the difference in this definition from previous
ones.

o ( g ( n )) = { f ( n ):  c > 0 ,  n

0

> 0 such that

 n  n

0

, we have 0  f ( n ) < cg ( n )}.

For a given function g ( n ), the set little- o :

w ( g ( n )) = { f ( n ):  c > 0 ,  n

0

> 0 such that

 n  n

0

, we have 0  cg ( n ) < f ( n )}.

w - notation

f ( n ) becomes arbitrarily large relative to g ( n ) as n
approaches infinity:

lim [ f ( n ) / g ( n )] = .

n 

g ( n ) is a lower bound for f ( n ) that is not
asymptotically tight.

For a given function g ( n ), the set little-omega: