Lesson 8: Functions and Growth - PowerPoint PPT Presentation

1 / 28
About This Presentation
Title:

Lesson 8: Functions and Growth

Description:

Big-O In Class. We want to prove that 3x3 - 2x 6 is O(x4) ... Horner's Method. 2x3 4x2 x 10 (evaluated at x=2) float a[] = {10 1 4 2} int order = 3; ... – PowerPoint PPT presentation

Number of Views:36
Avg rating:3.0/5.0
Slides: 29
Provided by: jwi6
Category:

less

Transcript and Presenter's Notes

Title: Lesson 8: Functions and Growth


1
Lesson 8 Functions and Growth
  • Objectives
  • Use big-O, big-Omega, and big-Theta notation
  • Find witnesses for function relationships
  • State basic properties of divisibility
  • Outline
  • Big O
  • Function Combinations
  • Big Omega
  • Big Theta
  • HW due Feb 15
  • 2.2 1, 5, 7, 14, 22, 45, 46, 47, 48
  • 2.3 4, 5, 7, 8, 9, 10, 13, 22
  • Reading Section 2.2

2
Section 2.2 Growth of Functions
  • Tools used in analyzing operations of hardware
    and execution of algorithms
  • Mainly concerned with asymptotic behavior
  • Three Notations
  • Big-O
  • Big-Omega
  • Big-Theta

3
Considerations
  • Three Costs
  • f(n) (1)n 10,000
  • g(n) (80)ln(n) 100,000
  • h(n) (0.01)n2 1

4
Big-O Notation
  • f, g are functions (Z or ?) ? ?
  • We say f(x) is O(g(x)) if there exists
    constants C and k
  • f(x) Cg(x) whenever x gt k
  • Reads f of x is big Oh of g of x
  • C, k are called witnesses

5
Big O
  • Show that ( f(x) 3x2 2x 8 ) is O(x2)

6
Big O
  • Show that (9x2) is O(x4)

7
Big-O estimates
  • Find a Big-O estimate of the sum of the first n
    positive integers.

8
Big O estimates
  • Show that f(x) n! is O(nn)

9
Common Growth functions
  • Page 138, Figure 3

10
Combinations
  • If f1(x) is O(g1(x)) and f2(x) is O(g2(x))
  • (f1 f2)(x)
  • If f1(x) is O(g(x)) and f2(x) is O(g(x))
  • (f1 f2)(x)
  • If f1(x) is O(g1(x)) and f2(x) is O(g2(x))
  • (f1 f2)(x)

11
Using Combo Rules
  • f(x) x3 x2 x 1
  • f(x) (2x 1)log(x)

12
Combinations In Class
  • Give a Big-O estimate for
  • n log(n) 2nnlog(n)(n! 2n)

13
Big-O In Class
  • We want to prove that 3x3 - 2x 6 is O(x4)
  • If we choose k 3, what is the smallest witness
    C that can be called to show this relationship?

14
Big Omega
  • f, g are functions (Z or ?) ? ?
  • We say f(x) is W(g(x)) if there exists
    constants C and k
  • f(x) Cg(x) whenever x gt k
  • Reads f of x is big Omega of g of x
  • C, k are called witnesses

15
Big Omega
  • Find witnesses C, k to prove that f(x) 12x3
    2x 1 is big-Omega(x3)

16
Big Theta
  • f, g are functions (Z or ?) ? ?
  • We say f(x) is Q(g(x)) if f(x) is O(g(x)) and
    f(x) is W(g(x))
  • f of x is big-theta of g of x
  • f of x is of order g of x

17
Big Theta
  • Show that 12x2 x 2 is Q(x2)

18
Algorithm Complexity
  • for (int i0 i lt x i)
  • for (int j0 j lt i j)
  • tmpVar1 x
  • tmpVar2 x
  • tmpVar3 tmpVar1 tmpVar3
  • myArrayji tmpVar3

19
Functions
  • What does it mean for a function to be W(1)?
  • If a function is Q(1), what can we say about the
    function?

20
Algorithms
  • A satisfactory algorithm must
  • Be correct
  • Efficient in time
  • Efficient in space
  • Time Complexity
  • Space Complexity

21
Binary Search Algorithm
  • Check to see if n is in a list of 2k sorted
    elements
  • a 2 18 19 20 29 30 102 3000

22
Linear Search
  • array an
  • target object x
  • j 0
  • while(j lt n x ! aj) j
  • if (j lt n) return j
  • else return 1
  • worst, best case

23
Linear Search Average Case (assuming in list)
  • if j1, 3 comparisons
  • if j 2, 5 comparisons
  • j n ____________
  • Average assume that element is equally likely to
    be in any spot.

24
Polynomial Calculation
  • 2x3 4x2 x 10 (evaluated at x2)
  • float a 10 1 4 2
  • int power 1 int order 3
  • float sum a0
  • for (j1 jltorder j)
  • power powerx
  • sum sum ajpower
  • return sum

25
Horners Method
  • 2x3 4x2 x 10 (evaluated at x2)
  • float a 10 1 4 2
  • int order 3
  • float sum aorder
  • for (j1 jltorder j)
  • sum sumx aorder-j
  • return sum

26
Circuit-Sat
  • Given boolean expression
  • of (an, an-1, a1, a0)
  • Is there a combination of ais which will make
    the circuit output a 1

27
Hard Problems
  • Polynomial Complexity
  • Tractable
  • Exponential Complexity
  • Intractable
  • Exponential algorithms may be polynomial in the
    average case
  • Approximations to exponential algorithms may be
    polynomial
  • Some problems are unsolvable
  • there exists no algorithm to solve all cases

28
NP-completeness
  • Class NP problems
  • Solutions can be checked in polynomial time
  • Class NP-complete problems
  • Can be converted to one another in polynomial
    time
  • If a polynomial solution for one is found, all
    are solved in P
Write a Comment
User Comments (0)
About PowerShow.com