Download presentation
Presentation is loading. Please wait.
1
Application: Efficiency of Algorithms I
Lecture 40 Section 9.3 Thu, Mar 31, 2005
2
Estimating Run Times Suppose the run-time of a program has growth rate (f(x)), where x is the input size. Then the run-time is (approx.) of the form t = cf(x) for some real number c.
3
Estimating Run Times Suppose the program runs in t0 seconds when the input size is x0. Then c = t0/f(x0). Thus, the run time is given by
4
Example: Estimating Run Time
Suppose a program has growth rate (x2) and that the program runs in t0 = 5 s when the input size is x0 = 100. Then the run time is given by t = 5(x2/1002) s. Thus, if input size were 500, then the run time would t = 55002/1002 = 125 s.
5
Example: Estimating Run Time
Suppose a program has growth rate (x log x). and that the program runs in t0 = 5 s when the input size is x0 = 100. Then the run time is
6
Example: Estimating Run Time
Thus, if input size were 500, then the run time would be
7
Comparison of Growth Rates
Consider programs with growth rates of (1), (log x), (x), (x log x), and (x2). Assume that each program runs in 1 s when the input size is 100. Calculate the run times for input sizes 102, 103, 104, 105, 106, and 107.
8
Comparison of Growth Rates
x (1) (log x) (x) (x log x) (x2) 102 1 s 1.0 s 103 1.5 s 10 s 15 s 100 s 104 2.0 s 200 s 10 ms 105 2.5 s 1 ms 2.5 ms 1 sec 106 3.0 s 30 ms 1.7 min 107 3.5 s 100 ms 350 ms 2.8 hrs
9
Comparison with (2x) Now consider a program with growth rate (2x).
Assume that the program runs in 1 s when the input size is 100. Calculate the run times for input sizes 100, 110, 120, 130, 140, and 150.
10
Comparison with (2x) x (x2) (2x) 100 1 s 110 1.2 s 1.0 ms 120
1.0 sec 130 1.7 s 18 min 140 2.0 s 13 days 150 2.3 s 36 yrs : 1000 100 s 2.7 x y
11
Comparison with (2x) x (x2) (2x) 100 1 s 110 1.2 s 1.0 ms 120
1.0 sec 130 1.7 s 18 min 140 2.0 s 13 days 150 2.3 s 36 yrs : 1000 100 s 2.7 x y x (1) (log x) (x) (x log x) (x2) 102 1 s 1.0 s 103 1.5 s 10 s 15 s 100 s 104 2.0 s 200 s 10 ms 105 2.5 s 1 ms 2.5 ms 1 sec 106 3.0 s 30 ms 1.7 min 107 3.5 s 100 ms 350 ms 2.8 hrs
12
Comparison with (2x) x (x2) (2x) 100 1 s 110 1.2 s 1.0 ms 120
1.0 sec 130 1.7 s 18 min 140 2.0 s 13 days 150 2.3 s 36 yrs : 1000 100 s 2.7 x y x (1) (log x) (x) (x log x) (x2) 102 1 s 1.0 s 103 1.5 s 10 s 15 s 100 s 104 2.0 s 200 s 10 ms 105 2.5 s 1 ms 2.5 ms 1 sec 106 3.0 s 30 ms 1.7 min 107 3.5 s 100 ms 350 ms 2.8 hrs
13
Comparison with (x!) Now consider a program with growth rate (x!).
Assume that the program runs in 1 s when the input size is 100. Calculate the run times for input sizes 100, 101, 102, 103, 104, and 105.
14
Comparison with (x!) x (2x) (x!) 100 1 s 101 2 s 101 s 102 4 s
10 ms 103 8 s 1.1 sec 104 16 s 1.8 min 105 32 s 3.2 hrs : 110 1.0 ms 5.4 x 106 y
15
Comparison with (x!) x (2x) (x!) 100 1 s 101 2 s 101 s 102 4 s
10 ms 103 8 s 1.1 sec 104 16 s 1.8 min 105 32 s 3.2 hrs : 110 1.0 ms 5.3 x 106 y x (x2) (2x) 100 1 s 110 1.2 s 1.0 ms 120 1.4 s 1.0 sec 130 1.7 s 18 min 140 2.0 s 13 days 150 2.3 s 36 yrs : 1000 100 s 2.7 x y
16
Comparison with (x!) x (2x) (x!) 100 1 s 101 2 s 101 s 102 4 s
10 ms 103 8 s 1.1 sec 104 16 s 1.8 min 105 32 s 3.2 hrs : 110 1.0 ms 5.3 x 106 y x (x2) (2x) 100 1 s 110 1.2 s 1.0 ms 120 1.4 s 1.0 sec 130 1.7 s 18 min 140 2.0 s 13 days 150 2.3 s 36 yrs : 1000 100 s 2.7 x y
17
Tractable vs. Intractable
Algorithms that are O(xd), for some d > 0, are considered tractable. Algorithms that are not O(xd), for some d > 0, are considered intractable. Of course, all algorithms are do-able for small input sizes. It is practical to factor small integers (< 50 digits). It is impractical to factor large integers (> 200 digits).
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.