170 likes | 186 Views
Application: Efficiency of Algorithms I. Lecture 40 Section 9.3 Thu, Mar 31, 2005. 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.
E N D
Application: Efficiency of Algorithms I Lecture 40 Section 9.3 Thu, Mar 31, 2005
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.
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
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.
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
Example: Estimating Run Time • Thus, if input size were 500, then the run time would be
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.
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.
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.
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).