Running Time Evaluation: Worst-Case and Average-Case Performance
Running Time Evaluation: Worst-Case and Average-Case Performance
1 / 14
Outline Time complexity Time growth Worst-case Average-case
1 Time complexity
2 Time growth
3 Worst-case
4 Average-case
2 / 14
Outline Time complexity Time growth Worst-case Average-case
Algorithm’s Efficiency
3 / 14
Outline Time complexity Time growth Worst-case Average-case
4 / 14
Outline Time complexity Time growth Worst-case Average-case
4 / 14
Outline Time complexity Time growth Worst-case Average-case
4 / 14
Outline Time complexity Time growth Worst-case Average-case
4 / 14
Outline Time complexity Time growth Worst-case Average-case
4 / 14
Outline Time complexity Time growth Worst-case Average-case
4 / 14
Outline Time complexity Time growth Worst-case Average-case
5 / 14
Outline Time complexity Time growth Worst-case Average-case
5 / 14
Outline Time complexity Time growth Worst-case Average-case
5 / 14
Outline Time complexity Time growth Worst-case Average-case
5 / 14
Outline Time complexity Time growth Worst-case Average-case
5 / 14
Outline Time complexity Time growth Worst-case Average-case
5 / 14
Outline Time complexity Time growth Worst-case Average-case
Informal Definition
6 / 14
Outline Time complexity Time growth Worst-case Average-case
For n◦ = 8:
f (n) 1 lg n lg2 n n n lg n n2 n3 2n
f (8) 1 lg 8 = 3 9 8 24 64 512 28 = 256
lg2 n n2 n3 2n
τ (n) = ff (n)
(8) 1 lg n
3 9
n
8
n lg n
24 64 512 28
= 2n−8
For simplicity: lg n ≡ log2 n
7 / 14
Outline Time complexity Time growth Worst-case Average-case
The largest data sizes n that can be processed by an algorithm with time
complexity f (n) provided that T (10) = 1 minute:
9 / 14
Outline Time complexity Time growth Worst-case Average-case
The largest data sizes n that can be processed by an algorithm with time
complexity f (n) provided that T (10) = 1 microsecond:
10 / 14
Outline Time complexity Time growth Worst-case Average-case
12 / 14
Outline Time complexity Time growth Worst-case Average-case
Advantages:
• An upper bound of the worst-case running time is usually
fairly easy to find.
• It is essential for so-called “mission-critical” applications
Drawbacks:
• It may be too pessimistic: actually encountered inputs may
lead to much lower running times that the “upper bound”.
• The most popular fast sorting algorithm, quicksort, is Θ(n2 )
in the worst case, but Θ(n log n) for “random” inputs, being
most frequent in practice.
• The worst-case input might be unlikely to be met in practice.
• In many cases it is difficult to specify the worst-case input.
13 / 14
Outline Time complexity Time growth Worst-case Average-case
14 / 14
Outline Time complexity Time growth Worst-case Average-case
14 / 14