+ All Categories
Home > Documents > ds5.pptx

ds5.pptx

Date post: 02-Jun-2018
Category:
Upload: madeehah-aatif
View: 218 times
Download: 0 times
Share this document with a friend

of 18

Transcript
  • 8/10/2019 ds5.pptx

    1/18

    COP 3530 Spring2012

    Data Structures & Algorithms

    Discussion Session Week 5

  • 8/10/2019 ds5.pptx

    2/18

    Outline

    Growth of functions

    Big Oh

    Omega

    Theta

    Little Oh

  • 8/10/2019 ds5.pptx

    3/18

    Growth of Functions

    Gives a simple view of the algorithms efficiency.

    Allows us to compare the relative performance of

    alternative algorithms.f1(n) is O(n)

    f2(n) is O(n^2)

  • 8/10/2019 ds5.pptx

    4/18

    Growth of Functions

    Exactrunning time of an algorithm is usually hardto

    compute, and its unnecessary.

    For large enough inputs, the lower-order terms ofan exact running time are dominated by high-order

    terms.

    f(n) = n^2 + 5n + 234n^2 >>5n + 234, when n is large enough

  • 8/10/2019 ds5.pptx

    5/18

    Asymptotic Notation: Big Oh (O)

    f(n)= O(g(n)) iff there exist positive constants c and n0 such thatf(n) cg(n) for all n n0

    O-notation to give an upper bound on a function

  • 8/10/2019 ds5.pptx

    6/18

    Asymptotic Notation: Big Oh (O)

    Example 1[linear function] f(n) = 3n+2For n >= 2, 3n+2

  • 8/10/2019 ds5.pptx

    7/18

    Asymptotic Notation: Big Oh (O)

    Example 2[quadric function] f(n) = 10n^2+4n+2

    For n >= 2, f(n) = 5, 5n < n^2.

    Hence for n>= n0 = 5, f(n)

  • 8/10/2019 ds5.pptx

    8/18

    Asymptotic Notation: Big Oh (O)

    Example 3[exponential function] f(n) = 6*2^n + n^2For n>=4, n^2

  • 8/10/2019 ds5.pptx

    9/18

    Asymptotic Notation: Big Oh (O)

    Example 5[loose bounds] f(n) = 3n+3

    For n >= 10, 3n+3

  • 8/10/2019 ds5.pptx

    10/18

    Asymptotic Notation: Big Oh (O)

    The specific values of cand n0used to satisfy the definition of bigoh are not important, we only say f(n) is big oh of g(n).

    c/n0 do NOTmatter, WHY?

    f(n)=n. Its close to 10n when comparing

    with n^2, n^3

    f(n) is relatively small when n

  • 8/10/2019 ds5.pptx

    11/18

    Asymptotic Notation: Omega Notation

    Big oh provides an asymptotic upperbound on a function.Omega provides an asymptotic lower bound on a function.

  • 8/10/2019 ds5.pptx

    12/18

    Asymptotic Notation: Omega Notation

    Example 7 f(n) = 3n+3 > 3n for all n. So f(n) = Omega(n)

    Example 8[loose bounds] f(n) = 3n+3 > 1 for all n, so f(n) =

    Omega(1)

  • 8/10/2019 ds5.pptx

    13/18

    Asymptotic Notation: Theta Notation

    Theta notation is used when functionfcan be bounded bothfrom above and belowby the same function g

  • 8/10/2019 ds5.pptx

    14/18

    Asymptotic Notation: Theta Notation

    Example 9: f(n) = 3n+3 is Theta(n), since n

  • 8/10/2019 ds5.pptx

    15/18

    Asymptotic Notation: Little oh (o)

    The asymptotic upper bound provided by O-notation may or maynotbe asymptotically tight. 2n = O(n) is tight, 2n = O(n^2) is not

    tight.

    We use o-notation to denote an upper bound that is NOT

    asymptotically tight.

  • 8/10/2019 ds5.pptx

    16/18

    Asymptotic Notation: Little oh (o)

    f(n) = o(g(n)) ifff(n) = O(g(n)) and f(n) !=Omega(g(n))

    Example 10 3n+2 = o(n^2) as 3n+2 = O(n^2) and 3n+2 !=

    Omega(n^2)

    Example 11 3n+2 != o(n) as 3n+2 = Omega(n)

  • 8/10/2019 ds5.pptx

    17/18

    Review

    Big oh: upperbound on a function.

    Omega: lower bound.

    Theta: lower and upper bound.- f(n) is Theta(g(n)) ifff(n) is O(g(n)) and Omega(g(n))

    Little oh: loose upper bound.

    - f(n) = o(g(n)) ifff(n) = O(g(n)) and f(n) !=Omega(g(n))

  • 8/10/2019 ds5.pptx

    18/18

    Office Hour This Week:

    Thursday 9thperiod at E309


Recommended