


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



Lisa Yan CS
Lecture Notes # April 6, 2020
Based on a handout by Mehran Sahami and Chris Piech
Although you may have thought you had a pretty good grasp on the notion of counting at the age of three, it turns out that you had to wait until now to learn how to really count. Aren’t you glad you took this class now?! But seriously, below we present some properties related to counting which you may find helpful in the future.
Sum Rule of Counting: If the outcome of an experiment can either be one of m outcomes or one of n outcomes, where none of the outcomes in the set of m outcomes is the same as the any of the outcomes in the set of n outcomes, then there are m + n possible outcomes of the experiment.
Rewritten using set notation, the Sum Rule states that if the outcomes of an experiment can either be drawn from set A or set B, where j Aj = m and jBj = n, and A \ B = ∅, then the number of outcomes of the experiment is j Aj + jBj = m + n.
Problem: You are running an on-line social networking application which has its distributed servers housed in two different data centers, one in San Francisco and the other in Boston. The San Francisco data center has 100 servers in it and the Boston data center has 50 servers in it. If a server request is sent to the application, how large is the set of servers it may get routed to?
Solution: Since the request can be sent to either of the two data centers and none of the machines in either data center are the same, the Sum Rule of Counting applies. Using this rule, we know that the request could potentially be routed to any of the 150 (= 100 + 50) servers.
Product Rule of Counting: If an experiment has two parts, where the first part can result in one of m outcomes and the second part can result in one of n outcomes regardless of the outcome of the first part, then the total number of outcomes for the experiment is mn.
Rewritten using set notation, the Product Rule states that if an experiment with two parts has an outcome from set A in the first part, where j Aj = m, and an outcome from set B in the second part (regardless of the outcome of the first part), where jBj = n, then the total number of outcomes of the experiment is j AjjBj = mn.
Note that the Product Rule for Counting is very similar to "the basic principle of counting" given in the Ross textbook.
Problem: Two 6-sided dice, with faces numbered 1 through 6, are rolled. How many possible outcomes of the roll are there?
Solution: Note that we are not concerned with the total value of the two dice, but rather the set of all explicit outcomes of the rolls. Since the first die 1 can come up with 6 possible values and the second die similarly can have 6 possible values (regardless of what appeared on the first die), the total number of potential outcomes is 36 (= 6 * 6). These possible outcomes are explicitly listed below as a series of pairs, denoting the values rolled on the pair of dice:
Problem: Consider a hash table with 100 buckets. Two arbitrary strings are independently hashed and added to the table. How many possible ways are there for the strings to be stored in the table?
Solution: Each string can be hashed to one of 100 buckets. Since the results of hashing the first string do not impact the hash of the second, there are 100 * 100 = 10,000 ways that the two strings may be stored in the hash table.
Inclusion-Exclusion Principle: If the outcome of an experiment can either be drawn from set A or set B, and sets A and B may potentially overlap (i.e., it is not guaranteed that A \ B = ∅), then the number of outcomes of the experiment is j A [ Bj = j Aj + jBj j A \ Bj.
Note that the Inclusion-Exclusion Principle generalizes the Sum Rule of Counting for arbitrary sets A and B. In the case where A \ B = ∅, the Inclusion-Exclusion Principle gives the same result as the Sum Rule of Counting since j∅j = 0.
1 “die” is the singular form of the word “dice” (which is the plural form).
Basic Pigeonhole Principle: For positive integers m and n, if m objects are placed in n buckets, where m > n, then at least one bucket must contain at least two objects.
In a more general form, this principle can be stated as:
General Pigeonhole Principle: For positive integers m and n, if m objects are placed in n buckets, then at least one bucket must contain at least ⌈mn⌉ objects.
Note that the generalized form does not require the constraint that m > n, since in the case where m n, we have ⌈mn⌉ = 1 , and it trivially holds that at least one bucket will contain at least one object.
Problem: Consider a hash table with 100 buckets. 950 strings are hashed and added to the table.
a) Is it possible that a bucket in the table contains no entries?
b) Is it guaranteed that at least one bucket in the table contains at least two entries?
c) Is it guaranteed that at least one bucket in the table contains at least 10 entries?
d) Is it guaranteed that at least one bucket in the table contains at least 11 entries?
Solution:
a) Yes. As one example, it is possible (albeit very improbable) that all 950 strings get hashed to the same bucket (say bucket 0). In this case bucket 1 would have no entries.
b) Yes. Since, 950 objects are placed in 100 buckets and 950 > 100, by the Basic Pigeonhole Principle, it follows that at least one bucket must contain at least two entries.
c) Yes. Since, 950 objects are placed in 100 buckets and ⌈ 950 100 ⌉ = ⌈ 9. 5 ⌉ = 10 , by the General Pigeonhole Principle, it follows that at least one bucket must contain at least 10 entries.
d) No. As one example, consider the case where the first 50 bucket each contain 10 entries and the second 50 buckets each contain 9 entries. This accounts for all 950 entries (50 * 10 + 50
For additional information on counting, you can consult a good discrete mathematics or probability textbook. Some of the discussion above is based on the treatment in:
K. Rosen, Discrete Mathematics and its Applications, 6th Ed. , New York: McGraw-Hill, 2007.