Académique Documents
Professionnel Documents
Culture Documents
1
The Sort Problems
Input
A sequence of numbers <a1, a2, …,an>
Output
A permutation (reordering) of the input sequence
such that a’1 ≦a’2 ≦… ≦a’n
A correct algorithm
Always produces the correct output for any input
For example:
Input <31,41,59,26,41,58>
>>>>>A correct algorithm<<<<<
<26,31,41,41,58,59>
Better means
Time
Space
Generally focusing on the worst-case number
of comparisons required to solve the
problem.
Selection Sort
n-1, n-2, n-3, …., 1
O(c1n2)
Merge Sort
T(n)=T(n/2) + T(n/2) + cn
…
T(n)=O(c2nlog2n)
Two machine
Machine A: 109 per second instructions
Machine B: 106 per seconds instructions
Supposed c1=2, c2=50
We want to sort 102 integers
Which one runs faster?
We want to sort 106 integers
Which one runs faster?
Manufacturing
Resources price
Human power price
Transportation price
Market
The place to set the
Factories
Warehouse
Stores
Hardware
GUI
Object-Oriented System
WAN, LAN
…
Edmund Landau
1877~1938
Inventor of the asymptotic notation
Donald E. Knuth
1938 ~
Turing Award, 1974.
Father of the analysis of algorithms
Popularizing the asymptotic notation
Ο
Ω
Θ
Sentence
Program p2 takes time O(n) to solve the problem.
Means
The time needed by p2 is a function f(n) with
f(n)=O(n)
Sentence
The comparison-based sort methods can not be
solved in O(n) time.
Means
The comparison-based sort problems can not be
solved in h(n) time, for any function h(n) with
h(n)=O(n)
Intuitive meaning
f(n) does not grow faster then g(n)
Comments
f(n)=O( g(n) ) roughly means f(n) ≦ g(n) in terms
of rate of growth
= is not the meaning of equation. It’s more like
We do not write O(g(n))=f(n)
n=O(n)?
999n=O(n)?
5n2=O(n3-n2)?
n2=O(n)?
Definition [Omega]
f(n) = Ω(g(n)) iff there exist positive constants
c and n0 such that f(n) ≥ cg(n) for all n, n ≥ n0.
The function g(n) is only a lower bound on f(n).
f(n) = Ω(g(n)) to be informative, g(n) should be
as large a function of n as one can come up
with for which f(n) = Ω(g(n)) is true.
Definition [Theta]:
f(n) = Θ(g(n)) iff there exist positive constants
c1, c2 and n0 such that c1g(n) ≤ f(n) ≤ c2g(n) for
all n, n ≥ n0.
Lower bound and upper bound on f(n)
The theta notation is more precise than
both “big oh” and omega notations.