note01-1x2

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

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

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

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

View Full Document
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 = 0 . 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 = 0 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 > 0 , c 2 > 0 , n 0 0 so that n n 0 , 0 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 ) . 0

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern