Computability - PowerPoint PPT Presentation

About This Presentation
Title:

Computability

Description:

Computability Sort homework. Formal definitions of time complexity. Big 0. Homework: Exercises. Searching. Shuffling. – PowerPoint PPT presentation

Number of Views:41
Avg rating:3.0/5.0
Slides: 17
Provided by: Jeani205
Category:

less

Transcript and Presenter's Notes

Title: Computability


1
Computability
  • Sort homework. Formal definitions of time
    complexity. Big 0.
  • Homework Exercises. Searching. Shuffling.

2
Reprise
  • Bubble sort
  • phases. Compare to neighbor and swap, if
    necessary. Only do next phase if there was a
    change.
  • Merge
  • divide in half. Sort each half and then merge
    (merge step easy/quick)

3
Reports
  • Insertion
  • Heap
  • Quicksort

4
My summaries
  • Insertion
  • Going i 2 to n, Put the ith element in its
    proper place. Simplest to write.
  • Heap
  • put data into a heap (max heap, binary tree)
    parent greater than each of child nodes. Remove
    root (the biggest). Re-build tree and repeat
  • Quicksort
  • choose pivot. Place items in sections less than
    pivot and greater than or equal to pivot
    (variation less than, equal, and greater than
    pivot). Repeat for each section. Depends on good
    choice of pivots
  • Random. Median. Median of median. Use knowledge
    of data.

5
Cards
  • Do sorts using cards.

6
Median
  • There are ways to get median or estimate of
    median or median of medians that do not involve
    sorting the whole list.
  • Extra credit opportunity!

7
O(f(n))
  • defines an upper bound. AKA called asymptotic
    notation.
  • Given two functions, f and gN ?R
  • then we say f(n) O(g(n)) or F(n) is O(gn)) g(n)
    is an asymptotic bound for f(n)
  • IF there exists positive integers c and n0 such
    that
  • f(n) lt cg(n) for ngt n0
  • Informally, for high enough values n, and a
    coefficient, g(n) is upper bound to f(n).

8
Examples
  • if f(n) 4n3100n21000, then f(n) O(n3)
  • Try n0 1000, c5.
  • Don't need to pick the lowest values.
  • Note it also is true that
  • f(n) O(n4). f(n) is . Note the equal sign is
    used but it is problematic.
  • But f(n) is not O(n2). f(n) will be more than
    cn2, no matter what choice of c, at some point.

9
Exercises
  • Find c and n0 and determine g(n) for f(n)
  • n4 1000000
  • 10n3100n100
  • Generalize about polynomials

10
logarithms
  • Recall logbn is the value e such that ben
  • Now
  • logbn logan / logab
  • Proof Show logbn logab logan. That is, a
    raised to expression on right is equal to n
  • Call X logbn, Y logab
  • aYX (aY)X by rules of exponentsaY is equal
    to b. bX is equal to n.

11
logarithms for O() notation
  • Can use log (or ln) without mentioning base
    because the difference is just a coefficient and
    Big Oh notation allows/uses a coefficient.

12
Note
  • f(n) log(n) is O(n)
  • nlog(n) is O(n2)
  • These are each strict bounds.

13
small o
  • Given functions f and g, then f(n) o(g(n))
  • if that for any cgt0, a number n0 exists such that
    f(n) ltcg(n) for ngtn0.
  • f(n) is asymptotically less.
  • Another way to say this is
  • lim (f(n)/g(n)) 0 as n ? infinity

14
Examples
  • n log(n) o(n2)
  • n2 o(n3)
  • sqrt(n) o(n)

15
Time complexity
  • let tN ? R (t a function from naturals to
    positive reals)
  • Time complexity class TIME(t(n)) is all languages
    that are decidable by an O(t(n)) time Turing
    machine.

16
Homework
  • Prove or disprove 100n O(n) n3
    O(n) 100n o(n) en o(3n)
  • Develop a way to shuffle cards. (Can do research)
  • Think of how to search a sorted for a particular
    value.
  • Extra credit research median algorithms to
    present to class.
Write a Comment
User Comments (0)
About PowerShow.com