note01-1x2 - Algorithm Analysis It means estimating the...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: Algorithm Analysis It means: estimating the recourses required. The resources of algorithms: time and space . We mainly consider time: harder to estimate; often more critical. The efficiency of an algorithm is measured by a runtime function T ( n ) . n is the size of the input. Strictly speaking, n is the # of bits needed to represent input. Commonly, n is the # of items in the input, if each item is of fixed size . This makes no difference in asymptotic analysis in most cases. c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 2 / 29 Example 1 An array of k int . Strictly speaking n = 32 k bits. However, since int has fixed size of 32 bits, we can use n = k as input size. Example 2 The input is one integer of k digits long. Since its size is not fixed ( k can be arbitrarily large). The input size is not n = 1 . It is n = 4 k bits long. c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 3 / 29 What’s T ( n ) ? Defining T ( n ) as the real run time is meaningless, because the real run time depends on many factors, such as the machine speed, the programming language used, the quality of compilers etc . These are not the properties of the algorithm. T ( n ) def = the number of basic instructions performed by the algorithm. Basic instructions: + ,- , * , / , read from/write into a memory location, comparison, branching to another instruction ... These are not basic instructions: input/output statement, sin ( x ) , exp ( x ) . . . . These actions are done by function calls, not by a single machine instruction. Knowing T ( n ) and the machine speed , we can estimate the real runtime . Example 3: The machine speed is 10 8 ins/sec. T ( n ) = 10 6 . The real runtime would be about 10- 8 × 10 6 = . 01 sec. c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 4 / 29 Example 4: Consider this simple program: 1: s = 2: for i = 1 to n do 3: for j = 1 to n do 4: s = s + i + j 5: end for 6: end for T ( n ) = ? It’s hard to get the exact expression of T ( n ) even for this very simple program. Also, the exact value of T ( n ) depends on factors such as prog language, compiler. These are not the properties of the loop. They should not be our concern. We can see: the loop iterates n 2 times , and loop body takes constant number of instructions. So T ( n ) = an 2 + bn + c for some constants a , b , c . We say the growth rate of T ( n ) is n 2 . This is the sole property of the algorithm and is our main concern. c Xin He (University at Buffalo) CSE 431/531 Algorithm Analysis and Design 5 / 29 Growth rate functions We want to define the precise meaning of growth rate . Definition 1: Θ( g ( n )) = { f ( n ) | ∃ c 1 > , c 2 > , n ≥ 0 so that ∀ n ≥ n , ≤ c 1 g ( n ) ≤ f ( n ) ≤ c 2 g ( n ) } If f ( n ) ∈ Θ( g ( n )) , we also write f ( n ) = Θ( g ( n )) and say: the growth rate of f ( n ) is the same as the growth rate of g ( n ) ....
View Full Document

This document was uploaded on 02/02/2010.

Page1 / 12

note01-1x2 - Algorithm Analysis It means estimating the...

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

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