51 Combinatorics

51 Combinatorics - Handout #51 March 3, 2008 CS103A Robert...

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

View Full Document Right Arrow Icon
Handout #51 CS103A March 3, 2008 Robert Plummer Combinatorics Combinatorics is the study of counting, which is important in Computer Science in many ways: To understand the performance of algorithms, we need to count the steps they execute We also need to count the amount of memory used as algorithms execute Counting is important in the study of probability, which is used in many algorithms and games Counting alternatives is often important in algorithm design Before we do anything formally, here are some warm-up questions: Suppose there are 18 math majors and 200 CS majors at Stanford. How many ways are there to pick one representative who is either a math major or a CS major? How many ways are there to pick two representatives, so that one is a math major and one is a CS major? How many ways are there to pick two representatives, regardless of their majors? Sum Rule and Product Rule The Sum Rule: If a task can be accomplished by choosing one of the n A alternatives in set A or by choosing one of the n B alternatives in set B, and if the sets A and B are disjoint, then there are n A + n B ways to accomplish the task. This can be generalized to any number of tasks. The Product Rule : If a task consists of a sequence of two subtasks, and there are n 1 ways to accomplish the first subtask, and for each of these there are n 2 ways to accomplish the second subtask, then there are n 1 n 2 ways to accomplish the overall task. This can be generalized to any number of tasks.
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Sets Before proceeding, we will give a few definitions concerning sets: A set is an unordered collection of distinct objects, which we call the elements of the set. The set of no elements is called the empty set . If A is a finite set, |A| denotes the number of elements in A, which is called the cardinality of A. The union of sets A and B, denoted A B, is the set of all elements in A or B. The intersection of sets A and B, denoted A B, is the set of all elements in both A and B. Generalized Sum and Product Rules The Sum Rule : If a task can be accomplished by choosing one of the alternatives from the sets S 1 , S 2 , . .., S m , and these sets are pairwise disjoint (i.e., S i S j = Ø for all i j), and n i is the number of elements in S i , then the number of ways to accomplish the task is n 1 + n 2 + . .. + n m . Using the notation of set theory, we would write |S 1 S 2 ... S m | = |S 1 | + |S 2 | + . .. + |S m | (where the sets are disjoint). The Product Rule : If E 1 , E 2 , . .., E m is a sequence of events such that E 1 can occur in n 1 ways and if E 1 , E 2 , . .., E k-1 have occurred, then E k can occur in n k ways, then there are n 1 n 2 ...n m ways in which the entire sequence of events can occur. Suppose you are either going to go to an Italian restaurant that serves 15 entrées or to a French restaurant that serves 10 entrées.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/01/2011 for the course CS 103A taught by Professor Plummer,r during the Winter '07 term at Stanford.

Page1 / 18

51 Combinatorics - Handout #51 March 3, 2008 CS103A Robert...

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

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