{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# mar5 - Illinois Institute of Technology Department of...

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

Illinois Institute of Technology Department of Computer Science Lecture 12: March 5 CS 330 Discrete Mathematics Spring Semester, 2008 1 Analysis of algorithms In this section, we will return to the problem that originally led us into the discussion of probability: For example, consider the algorithm to find the maximum of n numbers x 1 , x 2 , . . . , x n listed below. To analyze this algorithm fully we want to know exactly how many times each of the instructions is executed; but for the moment, let us ask only how many times the statement “ m k ” is executed. The answer, of course, depends not on the particular values of the x i , but rather on their relative order: If x 1 is the maximum of the n elements, the statement will never be executed. If x 1 < x 2 < · · · < x n then the statement will be executed n - 1 times. For how many of the relative arrangements of the inputs x 1 , x 2 , . . . , x n will the statement be executed exactly i times? The answer to this question is at the heart of the analysis of the algorithm. ALGORITHM 1: /* Selecting the largest of x [1] , x [2] , . . . , x [ n ] . */ m 1 FOR k 2 TO n DO IF x k > x m THEN m k | {z } “assignment” of interest

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