lec19 - CS 3110 Lecture 19 Analyzing running time with...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 3110 Lecture 19 Analyzing running time with recurrence relations Asymptotic complexity has limitations, but it is still a useful tool analyzing and improving program performance. The use of big-O notation simplifies the task of analyzing performance. For OCaml, we assume that all the reductions performed during evaluation take constant time, including all arithmetic operations and pattern matching. This assumption may be surprising if you think about the substitution work that seems to be required by the substitution model of evaluation: a substituted variable may appear at many different places in the code. The OCaml implementation avoids doing the work of substitution, by instead keeping track of all in-scope substitutions in a separate environment that allows variables to be looked up when their bindings are needed. The following multiplication routine is not very efficient: let rec times1(a, b) = if (b = 0) then 0 else a + times1(a, b-1) What is the order of growth of the time required by times1 as a function of n , where n is the magnitude of the parameter b ? Note that the "size" of a number can be measured either in terms of its magnitude or in terms of the number of digits (the space it takes to write the number down). Often the number of digits is used, but here we use the magnitude. Note that it takes only about log 10 x digits to write down a number of magnitude x , thus these two measures are very different. We assume that all the primitive operations in the times1 function ( if , + , = , and - ) and the overhead for function calls take constant time. Thus if n =0, the routine takes at most some constant time c 1 . If n >0, the
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

lec19 - CS 3110 Lecture 19 Analyzing running time with...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online