asymptotes why n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Asymptotes: Why? PowerPoint Presentation
Download Presentation
Asymptotes: Why?

Loading in 2 Seconds...

play fullscreen
1 / 11

Asymptotes: Why? - PowerPoint PPT Presentation


  • 78 Views
  • Uploaded on

Asymptotes: Why?. How to describe an algorithm’s running time? (or space, …). How does the running time depend on the input? T(x) = running time for instance x. Problem: Impractical to use, e.g., “15 steps to sort [3 9 1 7], 13 steps to sort [1 2 0 3 9], …”

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Asymptotes: Why?' - mills


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
asymptotes why
Asymptotes: Why?

How to describe an algorithm’s running time?

(or space, …)

How does the running time depend on the input?

T(x) = running time for instance x

Problem: Impractical to use, e.g.,

“15 steps to sort [3 9 1 7], 13 steps to sort [1 2 0 3 9], …”

Need to abstract away from the individual instances.

asymptotes why1
Asymptotes: Why?

Standard solution: Abstract based on size of input.

How does the running time depend on the input?

T(n) = running time for instances of size n

Problem: Time also depends on other factors.

E.g., on sortedness of array.

asymptotes why2
Asymptotes: Why?

Most common. Default.

Determining the input probability distribution can be difficult.

Solution: Provide a bound over these instances.

Worst case T(n) = max{T(x) | x is an instance of size n}

Best case T(n) = min{T(x) | x is an instance of size n}

Average case T(n) = |x|=n Pr{x}  T(x)

asymptotes why3
Asymptotes: Why?

What’s confusing about this notation?

Worst case T(n) = max{T(x) | x is an instance of size n}

Best case T(n) = min{T(x) | x is an instance of size n}

Average case T(n) = |x|=n Pr{x}  T(x)

Two different kinds of functions:

T(instance) T(size of instance)

Won’t use T(instance) notation again, so can ignore.

asymptotes why4
Asymptotes: Why?

Problem: T(n) = 3n2 + 14n + 27

Too much detail: constants may reflect implementation details & lower terms are insignificant.

Solution: Ignore the constants & low-order terms.(Omitted details still important pragmatically.)

3n2 > 14n+17

 “large enough” n

upper bounds
Upper Bounds

Creating an algorithm proves we can solve the problem within a given bound.

But another algorithm might be faster.

E.g., sorting an array.

Insertion sort  O(n2)

What are example algorithms for

O(1), O(log n), O(n), O(n log n), O(n2), O(n3), O(2n)?

lower bounds
Lower Bounds

Sometimes can prove that we cannot compute something without a sufficient amount of time.

That doesn't necessarily mean we know how to compute it in this lower bound.

E.g., sorting an array.

# comparisons needed in worst case  (n log n)

Shown in COMP 482.

definitions o
Definitions: O, 

T(n)  O(g(n))

 constants C,k > 0

such that

 nk, T(n)  Cg(n)

T(n) (g’(n))

 constants C’,k’ > 0

such that

 nk’, T(n)  C’g’(n)

Cg(n)

T(n)

C’g’(n)

k

k’

examples o
Examples: O, 

2n+13  O( ? )

Also, O(n2), O(5n), … Can always weaken the bound.

O(n)

2n+13  ( ? )

(n), also (log n), (1), …

2n O(n) ? (n) ?

Given a C, 2n  Cn, for all but small n.

(n), not O(n).

nlog n O(n5) ?

No. Given a C, log n  C5, for all large enough n. Thus, (n5).

definitions
Definitions: 

T(n)  (g(n))

T(n)  O(g(n)) and T(n)  (g(n))

Ideally, find algorithms that are asymptotically as good as possible.

notation
Notation

O(), (), () are sets of functions.

But common to abuse notation, writing

T(n) = O(…)

instead of T(n)  O(…)

as well as T(n) = f(n) + O(…)