cThese are just a few examples of data structures, and there are many more variations and specialized types. Understanding data structures is essential for designing efficient algorithms and writing high-performance software.
3. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Combinatronics
Combinatorics is the study of collections of objects. Specifically
, counting objects, arrangement, derangement, etc. along with
their mathematical properties.
Counting objects is important in order to analyze algorithms
and compute discrete probabilities
Originally, combinatorics was motivated by gambling: counting
configurations is essential to elementary probability
A simple example: How many arrangements are there of a deck of 52
cards?
In addition, combinatorics can be used as a proof technique
A combinatorial proof is a proof method that uses counting arguments
to prove a statement
4. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
The Basics of Counting
• Suppose that a password on a computer system consists of six,
seven, or eight characters. Each of these characters must be a
digit or a letter of the alphabet. Each password must contain at
least one digit. How many such passwords are there? The
techniques needed to answer this question and a wide variety of
other counting problems will be introduced.
• Two basic counting principles, the product rule and the sum rule
4
5. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Product Rule
• If two events are not mutually exclusive (that is we do them
separately), then we apply the product rule
• Theorem: Product Rule
Suppose a procedure can be accomplished with two disjoint su
btasks. If there are
– n1 ways of doing the first task and
– n2 ways of doing the second task,
then there are n1.n2 ways of doing the overall procedure
6. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Product Rule:
Suppose a procedure consists of 2 tasks
1
n ways to perform 1st task
2
n ways to perform 2nd task
2
1 n
n ways to perform procedure
7. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example: 2 employees 10 offices
How many ways to assign employees
to offices?
1st employee has 10 office choices
2nd employee has 9 office choices
Total office assignment ways: 10x9 = 90
8. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example: How many different variable names
with 2 symbols?
1st symbol
letter
26 choices
2nd symbol
alphanumeric
26+10 = 36 choices
Total variable name choices: 26x36 = 936
(e.g. A1, A2, AA)
XY
9. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Examples-1
The chairs of an auditorium are to be labeled with an uppercase
English letter followed by a positive integer not exceeding 100.
What is the largest number of chairs that can be labeled differently?
Solution:
The procedure of labeling a chair consists of two tasks, namely,
assigning to the seat one of the 26 uppercase English letters, and the
n assigning to it one of the 100 possible integers. The product rule
shows that there are 26*100=2600 different ways that a chair can
be labeled. Therefore, the largest number of chairs that can be
labeled differently is 2600.
9
10. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example 2
There are 32 microcomputers in a computer center. Each microc
omputer has 24 ports. How many different ports to a microcomp
uter in the center are there?
Solution: The procedure of choosing a port consists of two
tasks, first picking a microcomputer and then picking a port on
this microcomputer. Because there are 32 ways to choose the
microcomputer and 24 ways to choose the port no matter
which microcomputer has been selected, the product rule
shows that there are 32 · 24 = 768 ports.
10
11. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example- 3
How many different bit strings of length seven
are there?
Solution: Each of the seven bits can be chosen in
two ways, because each bit is either 0 or 1.
Therefore, the product rule shows there are a
total of 27 = 128 different bit strings of length
seven
11
12. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example-4
How many different license plates can be made if each p
late contains a sequence of three uppercase English lette
rs followed by three digits (and no sequences of letters a
re prohibited, even if they are obscene)?
Solution: There are 26 choices for each of the three upp
ercase English letters and ten choices for each of the thr
ee digits. Hence, by the product rule there are a total of
26 · 26 · 26 · 10 · 10 · 10 = 17,576,000 possible license
plates.
12
13. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Generalized Product Rule:
Suppose a procedure consists of tasks
1
n ways to perform 1st task
2
n ways to perform 2nd task
k
n
n
n
2
1 ways to perform procedure
k
k
n ways to perform th task
k
14. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example: How many different variable names
with exactly symbols?
1st symbol
letter
26 choices
Remaining symbols
alphanumeric
36 choices for each
Total choices:
(e.g. D1B…6)
1
k
1
1
k
Y
XY
1
)
36
(
26
36
36
26
k
1
k
15. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example-5
The Telephone Numbering Plan The North American numbering plan (NANP)
specifies the format of telephone numbers in the U.S., Canada, and many other
parts of North America. A telephone number in this plan consists of 10 digits,
which are split into a three-digit area code, a three-digit office code, and a four
-digit station code. Because of signaling considerations, there are certain restri
ctions on some of these digits. To specify the allowable format, let X denote a
digit that can take any of the values 0 through 9, let N denote a digit that can ta
ke any of the values 2 through 9, and let Y denote a digit that must be a 0 or a
1. Two numbering plans, which will be called the old plan, and the new plan,
will be discussed. As will be shown, the new plan allows the use of more num
bers. In the old plan, the formats of the area code, office code, and station code
are NYX, NNX, and XXXX, respectively, so that telephone numbers had the f
orm NYX-NNX-XXXX. In the new plan, the formats of these codes are NXX,
NXX, and XXXX, respectively, so that telephone numbers have the form NX
X-NXX-XXXX. How many different North American telephone numbers are
possible under the old plan and under the new plan?
15
17. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Solution:
By the product rule, there are 8 · 2 · 10 = 160 area codes with format NYX and
8 · 10 · 10 = 800 area codes with format NXX. Similarly, by the product rule, t
here are 8 · 8 · 10 = 640 office codes with format NNX. The product rule also
shows that there are 10 · 10 · 10 · 10 = 10,000 station codes with format XXX
X.
Consequently, applying the product rule again, it follows that under the old pln
there are
160 · 640 · 10,000 = 1,024,000,000
different numbers available in North America.
Under the new plan, there are 800 · 800 · 10,000 = 6,400,000,000 different nu
mbers available
17
18. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Sum Rule(1)
• If two events are mutually exclusive, that is, they can
not be done at the same time, then we must apply the
sum rule
• Theorem: Sum Rule. If
– an event e1 can be done in n1 ways,
– an event e2 can be done in n2 ways, and
– e1 and e2 are mutually exclusive
then the number of ways of both events occurring is
n1+ n2
19. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Sum Rule:
Suppose a procedure can be performed
with either of 2 different methods
1
n ways to perform 1st method
2
n ways to perform 2nd method
2
1 n
n ways to perform procedure
20. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example-1
• Suppose that either a member of the mathematics faculty or a student who is a
mathematics major is chosen as a representative to a university committee. How
many different choices are there for this representative if there are 37 members
of the mathematics faculty and 83 mathematics majors and no one is both a
faculty member and a student?
• Solution: There are 37 ways to choose a member of the mathematics faculty and
there are 83 ways to choose a student who is a mathematics major. Choosing a
member of the mathematics faculty is never the same as choosing a student who
is a mathematics major because no one is both a faculty member and a student.
By the sum rule it follows that there are 37 + 83 = 120 possible ways to pick this
representative.
• We can extend the sum rule to more than two tasks. Suppose that a task can be
done in one of n1 ways, in one of n2 ways, ... , or in one of nm ways.
20
21. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example-2
A student can choose a computer project from one of three lists.
The three lists contain 23, 15, and 19 possible projects,
respectively. No project is on more than one list. How many poss
ible projects are there to choose from?
Solution: The student can choose a project by selecting a project
from the first list, the second list, or the third list. Because no
project is on more than one list,
By the sum rule there are 23 + 15 + 19 = 57 ways to choose a
project.
21
22. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Sum Rule (2)
• There is a natural generalization to any sequence of m tasks;
namely the number of ways m mutually events can occur
n1 + n2 + … + nm-1 + nm
• We can give another formulation in terms of sets. Let A1, A2, …,
Am be pairwise disjoint sets. Then
|A1 A2 … Am | = |A1| |A2| … |Am|
(In fact, this is a special case of the general Principal of
Inclusion-Exclusion (PIE))
23. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example: Number of variable names with
1 or 2 symbols
Variables with 1 symbol: 26
Variables with 2 symbols: 936
Total number of variables: 26+936=962
24. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Principle of Inclusion-Exclusion
(PIE) The Subtraction rule
• Say there are two events, e1 and e2, for which there are n1 and n2 possible
outcomes respectively.
• Now, say that only one event can occur, not both
• In this situation, we cannot apply the sum rule. Why?
… because we would be over counting the number of possible outcomes.
• Instead we have to count the number of possible outcomes of e1 and e2
minus the number of possible outcomes in common to both; i.e., the
number of ways to do both tasks
• If again we think of them as sets, we have
|A1 A2| =|A1| + |A2| - |A1 A2|
25. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example:
Number of binary strings of length 8
that either start with 1 or end with 0
Strings that start with 1:
Strings that end with 0:
Total strings: 128+128-64=192
7
2
1
1 x
x
x 128 choices
0
7
2
1 y
y
y 128 choices
Common strings: 0
1 6
1 z
z 64 choices
27. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example-1
How many bit strings of length eight either start with a 1 bit or end with the
two bits 00?
Solution: We can construct a bit string of length eight that either starts with a 1 bit or en
ds with the two bits 00, by constructing a bit string of length eight beginning with a 1 bi
t or by constructing a bit string of length eight that ends with the two bits 00. We can co
nstruct a bit string of length eight that begins with a 1 in 2 7 = 128 ways. This follows b
y the product rule, because the first bit can be chosen in only one way and each of the o
ther seven bits can be chosen in two ways. Similarly, we can construct a bit string of le
ngth eight ending with the two bits 00, in 2 6 = 64 ways. This follows by the product ru
le, because each of the first six bits can be chosen in two ways and the last two bits can
be chosen in only one way. Some of the ways to construct a bit string of length eight sta
rting with a 1 are the same as the ways to construct a bit string of length eight that ends
with the two bits 00. There are2 5 = 32 ways to construct such a string. This follows by t
he product rule, because the first bit can be chosen in only one way, each of the second
through the sixth bits can be chosen in two ways, and the last two bits can be chosen in
one way. Consequently, the number of bit strings of length eight that begin with a 1 or
end with a 00, which equals the number of ways to construct a bit string of length eight
that begins with a 1 or that ends with 00,equals 128 + 64 − 32 = 160
27
28. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example-
2
• A computer company receives 350 applications from computer graduates for a
job planning a line of new Web servers. Suppose that 220 of these applicants
majored in computer science, 147 majored in business, and 51 majored both in
computer science and in business. How many of these applicants majored
neither in computer science nor in business?
28
29. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
More Complex Counting Problems
• Many counting problems cannot be solved using just the sum rule
or just the product rule. However, many complicated counting
problems can be solved using both of these rules in combination.
• Example1: Suppose statement labels in a programming language
can be either a single letter or a letter followed by a digit. Find
the number of possible labels. Solution:
• Use the product rule. 26 + 26 *10 = 286
29
30. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
• Each user on a computer system has a password, which is six to eight
characters long, where each character is an uppercase letter or a digit. Each p
assword must contain at least one digit. How many possible passwords are
there?
• Solution: Let P be the total number of passwords, and let P6, P7, and P8 be the
passwords of length 6, 7, and 8. By the sum rule P = P6 + P7 +P8.
• To find each of P6, P7, and P8 ,
• we find the number of passwords of the specified length composed of letters
and digits and subtract the number composed only of letters.
• We find that:
• P6 = 366−266 =2,176,782,336 −308,915,776 =1,867,866,560.
• P7 = 367−267 = 78,364,164,096 − 8,031,810,176 = 70,332,353,920.
• P8 = 368−268 = 2,821,109,907,456 −208,827,064,576 =2,612,282,842,880.
• Consequently, P = P6 + P7 + P8 = 2,684,483,063,360
30
Example-2
32. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
PIE (2)
• More generally, we have the following
• Lemma: Let A, B, be subsets of a finite set U. Then
1. |AB| = |A| + |B| - |AB|
2. |A B| min {|A|, |B|}
3. |A|B| = |A| - |AB| |A|-|B|
4. |A| = |U| - |A|
5. |AB| =|AB|-|AB|= |A|+|B|-2|AB|= |A|B|+ |B|A|
6. |A B| = |A||B|
33. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
PIE: Theorem
• Theorem: Let A1,A2, …,An be finite sets, then
|A1 A2 ...An|= i|Ai|
- i<j|Ai Aj|
+ i<j<k|Ai Aj Ak|
- …
+(-1)n+1 |A1A2...An|
Each summation is over
• all i,
• pairs i,j with i<j,
• triples with i<j<k, etc.
34. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
PIE Theorem: Example 1
• To illustrate, when n=3, we have
|A1 A2 A3|= |A1|+ |A2| +|A3|
- [|A1A2|+|A1A3|+|A2A3|]
+|A1 A2 A3|
35. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
PIE Theorem: Example 2
• To illustrate, when n=4, we have
|A1A2A3A4|= |A1|+|A2|+|A3|+|A4|
- [|A1A2|+|A1A3|+|A1A4|
+|A2A3|+|A2A4|+|A3A4|]
+ [|A1A2A3|+|A1A2A4|
+|A1A3A4|+|A2A3A4|]
- |A1 A2 A3 A4|
36. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
The Division Rule
There are n/d ways to do a task if it can be done using a procedur
e that can be carried out in n ways, and for every way w, exactly
d of the n ways correspond to way w.
We can restate the division rule in terms of sets: “If the finite set
A is the union of n pairwise disjoint subsets each with d elements,
then n = |A|/d.”
We can also formulate the division rule in terms of functions: “If
f is a function from A to B where A and B are finite sets, and that
for every value y ∈ B there are exactly d values x ∈ A such that
f (x) = y (in which case, we say that f is d-to-one), then |B| = |A|/d
.”
36
37. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Application of PIE: Example (1)
• How many integers between 1 and 300 (inclusive) are
– Divisible by at least one of 3,5,7?
– Divisible by 3 and by 5 but not by 7?
– Divisible by 5 but by neither 3 or 7?
• Let
A = {nZ | (1 n 300) (3|n)}
B = {nZ | (1 n 300) (5|n)}
C = {nZ | (1 n 300) (7|n)}
• How big are these sets? We use the floor function
|A| = 300/3 = 100
|B| = 300/5 = 60
|C| = 300/7 = 42
38. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Application of PIE: Example (2)
• How many integers between 1 and 300 (inclusive) are divisible
by at least one of 3,5,7?
Answer: |AB C|
• By the principle of inclusion-exclusion
|AB C|= |A|+|B|+|C|-[|AB|+|AC|+|BC|]+|ABC|
• How big are these sets? We use the floor function
|A| = 300/3 = 100 |AB| = 300/15 = 20
|B| = 300/5 = 60 |AC| = 300/21 = 14
|C| = 300/7 = 42 |BC| = 300/35 = 8
|ABC| = 300/105 = 2
• Therefore:
|AB C| = 100 + 60 + 42 - (20+14+8) + 2 = 162
39. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Application of PIE: Example-3
• How many integers between 1 and 300 (inclusive) are divisible
by 3 and by 5 but not by 7?
Answer: |(A B)C|
• By the definition of set-minus
|(A B)C| = |A B| - |A B C| = 20 – 2 = 18
• Knowing that
|A| = 300/3 = 100 |AB| = 300/15 = 20
|B| = 300/5 = 60 |AC| = 300/21 = 14
|C| = 300/7 = 42 |BC| = 300/35 = 8
|ABC| = 300/105 = 2
40. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Application of PIE: Example
• How many integers between 1 and 300 (inclusive) are divisible by 5 but by
neither 3 or 7?
Answer: |B(A C)| = |B| - |B (A C)|
• Distributing B over the intersection
|B (A C)| = |(B A) (B C)|
= |B A| + |B C| - | (B A) (B C) |
= |B A| + |B C| - | B A C |
= 20 + 8 – 2 = 26
• Knowing that
|A| = 300/3 = 100 |AB| = 300/15 = 20
|B| = 300/5 = 60 |AC| = 300/21 = 14
|C| = 300/7 = 42 |BC| = 300/35 = 8
|ABC| = 300/105 = 2
41. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Application of PIE: #Surjections
• The principle of inclusion-exclusion can be used to count the number of onto
(surjective) functions
• Theorem: Let A, B be non-empty sets of cardinality m, n with mn. Then
there are
42. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
#Surjections: Example
• How many ways of giving out 6 pieces of candy to 3 children if
each child must receive at least one piece?
• This problem can be modeled as follows:
– Let A be the set of candies, |A|=6
– Let B be the set of children, |B|=3
– The problem becomes “find the number of surjective mappings from A to
B” (because each child must receive at least one candy)
• Thus the number of ways is thus (m=6, n=3)
43. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example
How many bit strings of length four do not have two consecutive 1s?
Solution: The tree diagram in Figure displays all bit strings of length four without t
wo consecutive 1s. We see that there are eight bit strings of length four without two con
secutive 1s.
43
44. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Pigeonhole Principle
3 pigeons
2 pigeonholes
45. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
One pigeonhole contains 2 pigeons
3 pigeons
2 pigeonholes
46. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Pigeonhole Principle
• If there are more pigeons than there are roots (pigeonholes), for
at least one pigeonhole, more than one pigeon must be in it
• Theorem: If k+1 or more objects are placed in k boxes, then
there is at least one box containing two or more objects
• This principal is a fundamental tool of elementary discrete
mathematics.
• It is also known as the Dirichlet Drawer Principle or Dirichlet
Box Principle
47. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Pigeonhole Principle
• It is seemingly simple but very powerful
• The difficulty comes in where and how to apply it
• Some simple applications in Computer Science
– Calculating the probability of hash functions having a
collision
– Proving that there can be no lossless compression algorithm
compressing all files to within a certain ration
• Lemma: For two finite sets A,B there exists a bijection f:AB
if and only if |A|=|B|
48. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Generalized Pigeonhole Principle
• Theorem: If N objects are placed into k boxes then there is at
least one box containing at least
• Example1: In any group of 367 or more people, at least two of
them must have been born on the same date. Because there are
only 366 possible birthdays.
• Example 2: In any group of 27 English words, there must be at l
east two that begin with the same letter, because there are 26 lette
rs in the English alphabet.
49. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example:
How many students do we need to have so that
at least six receive same grade (A,B,C,D,F)?
?
N students (objects)
5
k grades (boxes)
6
k
N
at least six students receive
same grade
50. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
r
k
N
Smallest integer with
is smallest integer with 1
r
k
N
1
r
k
N
)
1
(
r
k
N 1
)
1
(
r
k
N
N
51. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
r
k
N
5
k
6
r
1
)
1
(
r
k
N
26
1
)
1
6
(
5
N
For our example:
students
We need at least 26 students
52. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example-1
Show that for every integer n there is a multiple of n that has only 0s
and 1s in its decimal expansion.
Solution: Let n be a positive integer. Consider the n + 1 integers 1, 11,
111, . . . , 11 . . . 1 (where the last integer in this list is the integer
with n + 1 1s in its decimal expansion). Note that there are n possible
remainders when an integer is divided by n.
Because there are n + 1 integers in this list, by the pigeonhole principle
there must be two with the same remainder when divided by n. The
larger of these integers less the smaller one is a multiple of n, which has
a decimal expansion consisting entirely of 0s and 1s.
52
53. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example-2
What is the least number of area codes needed to guarantee that the 25 million
phones in a state can be assigned distinct 10-digit telephone numbers?
(Assume that telephone numbers are of the form NXX-NXX-XXXX, where th
e first three digits form the area code, N represents a digit from 2 to 9 inclusive
, and X represents any digit.)
Solution: There are eight million different phone numbers of the form NXX-X
XXX Hence, by the generalized pigeonhole principle, among 25 million
telephones, at least 25,000,000/8,000,000⊕ = 4 of them must have identical
phone numbers. Hence, at least four area codes are required to ensure that all
10-digit numbers are different.
53
54. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example-3
Suppose that a computer science laboratory has 15 work
stations and 10 servers. A cable can be used to directly
connect a workstation to a server. For each server, only
one direct connection to that server can be active at any
time. We want to guarantee that at any time any set of 1
0 or fewer workstations can simultaneously access
different servers via direct connections. Although we
could do this by connecting every workstation directly
to every server (using 150 connections), what is the
minimum number of direct connections needed to
achieve this goal.
54
55. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Solution:
Suppose that we label the workstations W1, W2, . . . , W15 and the serversS1, S2, . . . ,
S10 . Furthermore, suppose that we connect Wk to Sk for k = 1, 2, . . . , 10 and each of
W11, W12, W13, W14 , and W15 to all 10 servers. We have a total of 60 direct
connections.
Clearly any set of 10 or fewer workstations can simultaneously access different servers.
We see this by noting that if workstation Wj is included with 1 ≤ j ≤ 10, it can access
server Sj , and for each workstation W k with k ≥ 11 included, there must be a
correspondng workstation W with 1 ≤ j ≤ 10 not included, so Wk can access server Sj .
(This follows because there are at least as many available servers Sj as there are workst
ations Wj with 1 ≤ j ≤ 10 not included.)
Now suppose there are fewer than 60 direct connections between workstations and serv
ers. Then some server would be connected to at most 59/10 = 5 workstations. (If all
servers were connected to at least six workstations, there would be at least 6 · 10 = 60
direct connections.)
This means that the remaining nine servers are not enough to allow the other 10
workstations to simultaneously access different servers. Consequently, at least 60 direct
connections are needed. It follows that 60 is the answer.
55
56. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Generalized Pigeonhole Principle
• A probabilistic generalization states that
– if n objects are randomly put into m boxes
– with uniform probability
– (i.e., each object is place in a given box with probability
1/m)
– then at least one box will hold more than one object with
probability
57. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Generalized Pigeonhole Principle:
Example-1
• Among 10 people, what is the probability that two or
more will have the same birthday?
– Here n=10 and m=365 (ignoring leap years)
– Thus, the probability that two will have the same birthday
is
So, less than 12% probability
58. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Pigeonhole Principle: Example-2
• Show that
– in a room of n people with certain acquaintances,
– some pair must have the same number of acquaintances
• Note that this is equivalent to showing that any symmetric,
irreflexive relation on n elements must have two elements with the
same number of relations
• Proof: by contradiction using the pigeonhole principle
• Assume, to the contrary, that every person has a different number
of acquaintances: 0, 1, 2, …, n-1 (no one can have n acquaintances
because the relation is irreflexive).
• There are n possibilities, we have n people, we are not done
59. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Pigeonhole Principle: Example -3
• Assume, to the contrary, that every person has a different number
of acquaintances: 0, 1, 2, …, n-1 (no one can have n acquaintances
because the relation is irreflexive).
• There are n possibilities, we have n people, we are not done
• We need to use the fact that acquaintanceship is a symmetric
irreflexive relation
• In particular, some person knows 0 people while another knows
n-1 people
• This is impossible. Contradiction! So we do not have 10
possibilities, but less
• Thus by the pigeonhole principle (10 people and 9 possibilities) at
least two people have to the same number of acquaintances
60. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Pigeonhole Principle: Example 4
• Example: Say, 30 buses are to transport 2000 Cornhusker fans to Colorado.
Each bus has 80 seats.
• Show that
– One of the buses will have 14 empty seats
– One of the buses will carry at least 67 passengers
• One of the buses will have 14 empty seats
– Total number of seats is 80.30=2400
– Total number of empty seats is 2400-2000=400
– By the pigeonhole principle: 400 empty seats in 30 buses, one must have
400/30 = 14 empty seats
• One of the buses will carry at least 67 passengers
– By the pigeonhole principle: 2000 passengers in 30 buses, one must have
2000/30 = 67 passengers
61. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example: Counting Functions (1)
• Let S,T be sets such that |S|=n, |T|=m.
– How many function are there mapping f:ST?
– How many of these functions are one-to-one (injective)?
• A function simply maps each si to one tj, thus for each n we
can choose to send it to any of the elements in T
• Each of these is an independent event, so we apply the
multiplication rule:
• If we wish f to be injective, we must have nm, otherwise the
answer is obviously 0
62. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example: Counting Functions (2)
• Now each si must be mapped to a unique element in T.
– For s1, we have m choices
– However, once we have made a mapping, say sj, we cannot map subsequent
elements to tj again
– In particular, for the second element, s2, we now have m-1 choices, for s3, m-2
choices, etc.
• An alternative way of thinking is using the choose operator: we need to
choose n element from a set of size m for our mapping
• Once we have chosen this set, we now consider all permutations of the
mapping, that is n! different mappings for this set. Thus, the number of such
mapping is
63. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Example: Sets
• How many k integers 1k100 are divisible by 2 or 3?
• Let
– A = {nZ | (1 n 100) (2|n)}
– B = {nZ | (1 n 100) (3|n)}
• Clearly, |A| = 100/2 = 50, |B| = 100/3 = 33
• Do we have |AB| = 83? No!
• We have over counted the integers divisible by 6
– Let C = {nZ | (1 n 100) (6|n)}, |C| = 100/6 = 16
• So |AB| = (50+33) – 16 = 67
64. BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
Thank You
64