Download Running time - Jacobs University

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Apple II graphics wikipedia , lookup

2.5D wikipedia , lookup

General-purpose computing on graphics processing units wikipedia , lookup

Video card wikipedia , lookup

Framebuffer wikipedia , lookup

Graphics processing unit wikipedia , lookup

Computer vision wikipedia , lookup

Tektronix 4010 wikipedia , lookup

Waveform graphics wikipedia , lookup

Molecular graphics wikipedia , lookup

Transcript
Running time
• The running time depends on the input:
an already sorted sequence is easier to sort.
• Parameterize running time by the size of the input:
short sequences are easier to sort than long ones.
• Generally, we seek upper bounds on the running time:
we would like to have a guarantee.
Jacobs University
Visualization and Computer Graphics Lab
320201: Fundamental CS I (Algorithms and Data Structures)
37
1.3 Asymptotic analysis
Jacobs University
Visualization and Computer Graphics Lab
320201: Fundamental CS I (Algorithms and Data Structures)
38
Types of analyses
• Worst case: (usually)
T(n) = maximum time of algorithm on any input of size n.
• Average case: (sometimes)
T(n) = expected time of algorithm over all inputs of size n.
(Need assumption of statistical distribution of inputs.)
• Best case: (never)
Does not make much sense, e.g., we can start with
solution.
Jacobs University
Visualization and Computer Graphics Lab
320201: Fundamental CS I (Algorithms and Data Structures)
39
Asymptotic analysis
• What is Insertion Sort’s worst-case time?
It depends on the speed of our computer:
relative speed (on the same machine),
absolute speed (on different machines).
• Idea: Ignore machine-dependent constants.
Look at growth of T(n) as n→∞.
Jacobs University
Visualization and Computer Graphics Lab
320201: Fundamental CS I (Algorithms and Data Structures)
40
Asymptotically tight bound: Θ-notation
• For a given asymptotically non-negative function g(n),
we define
We write f(n) = Θ(g(n))
instead of f(n) є Θ(g(n)).
Example:
3n3 + 90n2 – 5n + 6046 = Θ(n3)
Jacobs University
Visualization and Computer Graphics Lab
320201: Fundamental CS I (Algorithms and Data Structures)
41
Asymptotic performance
• When n gets large enough,
a Θ(n2) algorithm always beats a Θ(n3) algorithm.
Jacobs University
Visualization and Computer Graphics Lab
320201: Fundamental CS I (Algorithms and Data Structures)
42
Asymptotic analysis
• We should not ignore asymptotically slower
algorithms, however.
• Real-world design situations often call for a careful
balancing of engineering objectives.
• Asymptotic analysis is a useful tool to help to
structure our thinking.
Jacobs University
Visualization and Computer Graphics Lab
320201: Fundamental CS I (Algorithms and Data Structures)
43
Asymptotically upper bound: O-notation
• For a given asymptotically non-negative function g(n),
we define
Example: We say that
f(n) is polynomially bounded, if
f(n) = O(nk) for some constant k.
Jacobs University
Visualization and Computer Graphics Lab
320201: Fundamental CS I (Algorithms and Data Structures)
44
Asymptotically lower bound: Ω-notation
• For a given asymptotically non-negative function g(n),
we define
For tight bounds, we get
Θ(g(n)) = O(g(n)) Ω(g(n))
Jacobs University
Visualization and Computer Graphics Lab
320201: Fundamental CS I (Algorithms and Data Structures)
45
Non-tight upper bound: o-notation
• For a given asymptotically non-negative function g(n),
we define
• f(n) = o(g(n)) implies
• Example: nb = o(an) for a > 1.
Jacobs University
Visualization and Computer Graphics Lab
320201: Fundamental CS I (Algorithms and Data Structures)
46
Non-tight lower bound: ω-notation
• For a given asymptotically non-negative function g(n),
we define
• f(n) = ω(g(n)) implies
Jacobs University
Visualization and Computer Graphics Lab
320201: Fundamental CS I (Algorithms and Data Structures)
47
Asymptotic analysis of Insertion Sort
• ck is the number of steps a computer needs to perform
instruction k once (e.g., a Random Access Machine).
• tj is the number of times the while-loop is executed in
for-iteration j.
Jacobs University
Visualization and Computer Graphics Lab
320201: Fundamental CS I (Algorithms and Data Structures)
48
Asymptotic analysis of Insertion Sort
Worst case:
Input series was ordered in reverse.
Then, tj = j.
With the arithmetic series
the worst-case asymptotic complexity is
Jacobs University
Visualization and Computer Graphics Lab
320201: Fundamental CS I (Algorithms and Data Structures)
49