Understanding Asymptotic Notations & Time Complexity: Big O, Worst, Best, Average Cases, Study notes of Data Structures and Algorithms

An in-depth explanation of time complexity, asymptotic notations, and the significance of worst, best, and average cases. It covers the concepts of big o notation, the difference between upper and lower bounds, and the properties of o notation. The document also includes examples and explanations of various growth rates, such as polynomial, exponential, and logarithmic functions.

Typology: Study notes

2010/2011

Uploaded on 09/01/2011

visir66
visir66 🇮🇳

4.4

(74)

97 documents

1 / 25

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Time complexity
Asymptotic Notations
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19

Partial preview of the text

Download Understanding Asymptotic Notations & Time Complexity: Big O, Worst, Best, Average Cases and more Study notes Data Structures and Algorithms in PDF only on Docsity!

Time complexity

Asymptotic Notations

Worst/ best/average cases

  • (^) Worst case is the longest running time for any input of size n
  • (^) O-notation represents upper bound I.e. an upper bound for worst case.
  • (^) Best case is the input data set that results in best possible performance.You cannot do better. This is lower bound.
  • (^) Average case is the average performance
  • (^) A non negative function T(n) is said to be O(f(n)) provided there exists a constant c>0 and an integer n 0 > 0 such that
  • (^) T(n)c. f(n) for all integer n > n 0
  • (^) Consider 1/3 n^2 – 5n
  • (^) The dominating term is n^2
  • (^) Therefore it should be of O(n^2 )
  • (^) Given a positive constant c , a positive integer n 0 to be found such that
  • (^) 1/3 n^2 - 5 nc n^2
  • (^) Suppose T(n) = 1/3 n^3 + ½ n^2 + 1/6 n
  • (^) So T(n) (1/3 n^3 ) which can be proved as follows
  • (^) 1/3 n^3 + ½ n^2 + 1/6 nc 1/3 n^3
  • (^) 1/3 + 1/(2n) + 1/(6n^2 )c/
  • (^) Inequality is valid for case c3 and integers n1
  • (^) O( g ) - the set of functions that grow no faster than g.
  • (^) g(n) describes the worst case behaviour of an algorithm that is O( g )
  • (^) O( g ) - the set of functions that grow no faster than g.
  • (^) g(n) describes the worst case behaviour of an algorithm that is O( g )
  • (^) Two additional notations

 ( g )

  • the set of functions, f, such that f(n) > c g(n) for some constant, c , and n > N g is a lower bound for f

Properties of the O notation

  • (^) Constant factors may be ignored  (^) k > 0 kf  is O( f)

Properties of the O notation

  • (^) Constant factors may be ignored  (^) k > 0 kf  is O( f)
  • (^) Higher powers grow faster
    • (^) n r^  is O( n s ) if 0  r  s

Properties of the O notation

  • (^) Constant factors may be ignored  k > 0 kf  is O( f)
  • (^) Higher powers grow faster
    • (^) n r^  is O( n s ) if 0  r  s  (^) Fastest growing term dominates a sum
    • (^) If f is O(g) , then f + g is O(g) eg an^4 + bn^3 is O(n^4 )  (^) Polynomial’s growth rate is determined by leading term
    • (^) If f is a polynomial of degree d , then f is O(nd)

Properties of the O notation

  • (^) f is O(g) is transitive
    • (^) If f is O(g) and g is O(h) then f is O(h)

Properties of the O notation

  • (^) f is O(g) is transitive
    • (^) If f is O(g) and g is O(h) then f is O(h)
  • (^) Product of upper bounds is upper bound for the product - (^) If f is O(g) and h is O(r)  then fh is O(gr)
  • (^) Exponential functions grow faster than powers
    • (^) n k^  is O( b n^ )  b > 1 and k  0 eg n^20 is O( 1.05 n)

Properties of the O notation

  • (^) f is O(g) is transitive
    • (^) If f is O(g) and g is O(h) then f is O(h)
  • (^) Product of upper bounds is upper bound for the product
    • (^) If f is O(g) and h is O(r)  then fh is O(gr)
  • (^) Exponential functions grow faster than powers
    • (^) n k^  is O( b n^ )  b > 1 and k  0 eg n^20 is O( 1.05 n)
  • (^) Logarithms grow more slowly than powers
    • (^) log bn  is O( n k )  b > 1 and k  0 eg log 2 n is O( n 0.5 )

Properties of the O notation

  • (^) All logarithms grow at the same rate
    • (^) log bn^ is^ O( log dn)^ ^ b, d > 1

Properties of the O notation

  • (^) All logarithms grow at the same rate
    • (^) log bn^ is^ O( log dn)^ ^ b, d > 1
  • (^) Sum of first n rth^ powers grows as the (r+ 1 )th^ power

 kr^  is  ( nr +1^ )

eg  i = is ( n^2 )

k = n k = n n(n+ 1 ) 2