Professional Documents
Culture Documents
Structures
Simonas Šaltenis
Nykredit Center for Database Research
Aalborg University
simas@cs.auc.dk
Correctness Robustness
Adaptability
Efficiency
Reusability
do A[i+1]=A[i] c5 nj 2
(t j 1)
i-- c6 j 2 j
(t 1)
A[i+1]:=key c7 n-1
6n
5n
4n
3n
2n
1n
worst-case
6n average-case
Running time
5n
best-case
4n
3n
2n
1n
1 2 3 4 5 6 7 8 9 10 11 12 …..
Input instance size
September 10, 2001 19
Best/Worst/Average Case (4)
Worst case is usually used:
It is an upper-bound and in certain application
domains (e.g., air traffic control, surgery)
knowing the worst-case time complexity is of
crucial importance
For some algorithms worst case occurs fairly
often
The average case is often as bad as the
worst case
Finding the average case can be very difficult
1,00E+09
1,00E+08
n
log n
1,00E+07
sqrt n
n log n
1,00E+06
100n
n^2
1,00E+05
T(n)
n^3
1,00E+04
1,00E+03
1,00E+02
1,00E+01
1,00E+00
1,00E-01
2 4 8 16 32 64 128 256 512 1024
n
1,00E+143
1,00E+131
1,00E+119 n
log n
1,00E+107
sqrt n
1,00E+95 n log n
100n
1,00E+83 n^2
T(n)
n^3
1,00E+71
2^n
1,00E+59
1,00E+47
1,00E+35
1,00E+23
1,00E+11
1,00E-01
2 4 8 16 32 64 128 256 512 1024
n
2 5 4 10 7; 5 2
2 5 4 10 7; 9 NIL
2 4 5 7 10; 5 2
2 4 5 7 10; 9 NIL
left=1
right=length(A)
do
j=(left+right)/2
if A[j]==q then return j
else if A[j]>q then right=j-1
else left=j+1
while left<=right
return NIL