This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Illinois Institute of Technology Department of Computer Science Lecture 4: February 4, 2008 CS 330 Discrete Structures Spring Semester, 2008 This lecture presents some elementary techniques for counting the number of configurations satisfying spec ified properties. Such techniques are fundamental to the analysis of algorithms, especially algorithms for sorting, searching, merging, and other problems of a combinatorial nature. For example, consider the algorithm listed below that finds the maximum of n numbers x [1] , x [2] , . . . , x [ n ]. 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  i 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 k times? The answer to this question is at the heart of the analysis of the algorithm. m  1 FOR i := 2 TO n DO IF x [ i ] > x [ m ] THEN /* x [ i ] is the largest seen so far */ m  i 1 The Rules of Sum and Product In order to have as wide an applicability as possible, we will talk in terms of how many ways an event can occur. What is an event? That depends on the context. It could be picking an orange, speckled sock from your sock drawer; it could be seating a group of five cannibals, three vegetarians, and a chicken at a table in such a way that nothing gets eaten ; it could be the choosing an arrangement of x [1], x [2], . . . , x [ n ] that causes the statement m  i in the algorithm above to be executed k times. In counting the number of ways an event can happen, we try to break the event down into simpler events whose combination results in the event under study. For instance, if we are trying to determine the number of ways that the roll of a pair of dice can result in a seven, we could consider the roll of each die to be a simpler event than the roll of the pair. There are two basic rules for counting the number of ways that simpler events can be combined to result in more complex events: Rule of Sum If an event E 1 can occur in e 1 different ways and a separate event E 2 can occur in e 2 different ways, the compound event E 1 E 2 can occur in e 1 + e 2 different ways. Rule of Product If an event E 1 can occur in e 1 different ways and a separate event E 2 can occur in e 2 different ways, the compound event E 1 E 2 can occur in e 1 e 2 different ways....
View
Full
Document
This note was uploaded on 04/15/2008 for the course CS 330 taught by Professor Reingold,edwardm. during the Spring '08 term at Illinois Tech.
 Spring '08
 Reingold,EdwardM.
 Computer Science

Click to edit the document details