Professional Documents
Culture Documents
Lecture 15
1 / 67
Probability Joke
2 / 67
A little bit of history
Founding fathers
Probability theory began in 17th century France in the
correspondence of two great French mathematicians, Blaise Pascal
and Pierre de Fermat.
4 / 67
Why probability is important for Computer Science?
5 / 67
Why probability is important for Computer Science?
Beyond these engineering applications, an understanding of
probability gives insight into many daily problems, such as
polling;
weather prediction;
DNA testing;
data analytics
actuarial sciences (insurance);
risk assessment;
financial investing;
gambling.
Probably!
6 / 67
Back to history
Consider a dice game that played an important role in the historical
development of probability.
Chevalier de Mere
7 / 67
Back to history
It is claimed that de Mere lost with 24 and felt that 25 rolls were
necessary to make the game favorable.
8 / 67
Back to history
The probability that no 6 turns up on the first toss is
5/6
0.518
Similarly, for the second bet, with 24 rolls, the probability that de
Mere wins is 24
35
1− = 0.491
36
and for 25 rolls it is 25
35
1− = 0.506
36
10 / 67
What is a probability problem?
11 / 67
Discrete Probability
Example
Toss a coin (another experiment) with possible outcomes: H (heads)
and T (tails).
Example
Outcomes of two tosses of a coin (experiment) are: {HH, HT, TH, TT }
12 / 67
Discrete Probability
13 / 67
Discrete Probability
Definition
A random variable is the expression whose value is the outcome of a
particular experiment.
Let X be the random variable which represents the roll of one die and
assign probabilities to the possible of X.
m ( ω1 ) + m ( ω2 ) + . . . + m ( ω6 ) = 1
Definition
Suppose we have an experiment whose outcome depends on chance.
We represent the outcome of the experiment by a capital Roman
letter, such as X, called a random variable. The sample space of the
experiment is the set of all possible outcomes. If the sample space is
either finite or countably infinite, the random variable is said to be
discrete. Sample space usually is denoted by Ω.
Definition
The elements of a sample space are called outcomes. Each subset of a
sample space is defined to be an event. Normally, we shall denote
outcomes by lower case letters and events by capital letters.
15 / 67
Discrete Probability
Example
A die is rolled once. We let X denote the outcome of this experiment.
Then the sample space for this experiment is the 6−element set
Ω = {1, 2, 3, 4, 5, 6}
E = {2, 4, 6}
16 / 67
Discrete Probability
Definition
Let X be a random variable which denotes the value of the outcome
of a certain experiment with finitely many possible outcomes. Let Ω
be the sample space of the experiment (i.e., the set of all possible
values of X, or equivalently, the set of all possible outcomes of the
experiment.) A distribution function for X is a real-valued function
m whose domain is Ω and which satisfies:
17 / 67
Discrete Probability
Example
For rolling a die,
1
m(i) = , i = 1, 2, . . . , 6
6
Clearly, it is a distribution function. Then
18 / 67
Discrete Probability
Example
Consider tossing a coin twice. There are several ways to record the
outcomes of this experiment: Record the two tosses, in the order they
occurred:
Ω1 = {HH, HT, TH, TT }
Record the outcomes by simply recording the number of heads that
appeared:
Ω2 = {0, 1, 2}
Finally, Record the two outcomes, without regard to the order in
which they occurred:
Ω3 = {HH, HT, TT }.
19 / 67
Discrete Probability
Example (Contd.)
Assume that all four outcomes are equally likely, and define the
distribution function m(ω ) by
1
m(HH ) = m(HT ) = m(TH ) = m(TT ) =
4
Let E = {HH, HT, TH }. Then
1 1 1 3
P(E) = m(HH ) + m(HT ) + m(TH ) = + + =
4 4 4 4
Similarly, if F = {HH, HT } then
1 1 1
P(F) = m(HH ) + m(HT ) = + =
4 4 2
20 / 67
Discrete Probability
Example
3 people, A, B, and C, are running for the same office, and assume
that one and only one of them wins. The sample space may be taken
as the 3−element set Ω = {A, B, C}. Suppose that A and B have the
same chance of winning, but that C has only 1/2 the chance of A or B.
Then we assign
m(A) = m(B) = 2m(C)
Since
m(A) + m(B) + m(C) = 1
we see that
2m(C) + 2m(C) + m(C) = 1
which implies that
5m(C) = 1
21 / 67
Discrete Probability
Example (Contd.)
Ω = {A, B, C}
Ω A B C
m 2/5 2/5 1/5
Let E be the event that either A or C wins. Then E = {A, C}, and
2 1 3
P(E) = m(A) + m(C) = + =
5 5 5
22 / 67
Properties of probability
Theorem
The probabilities assigned to events by a distribution function on a sample
space Ω satisfy the following properties:
23 / 67
Properties of probability
Theorem
Let A1 , . . . , An be pairwise disjoint events with Ω = A1 ∪ . . . ∪ An and let
E be any event. Then
n
P(E) = ∑ P(E ∩ Ai )
i=1
Corollary
For any two events A and B,
25 / 67
Properties of probability
Theorem
If A and B are subsets of Ω, then
26 / 67
Tree Diagrams
Example
Consider three tosses of a coin.
27 / 67
Tree Diagrams
Start
H T 1st Toss
H T H T 2nd Toss
H T H T H T H T 3rd Toss
28 / 67
Tree Diagrams
Start
H T 1st Toss
H T H T 2nd Toss
H T H T H T H T 3rd Toss
ω1 ω2 ω3 ω4 ω5 ω6 ω7 ω8 ← outputs
28 / 67
Tree Diagrams
Start
H T 1st Toss
H T H T 2nd Toss
H T H T H T H T 3rd Toss
ω1 ω2 ω3 ω4 ω5 ω6 ω7 ω8 ← outputs
HHH HHT HTH HTT THH THT TTH TTT
28 / 67
Tree diagrams
Example (Contd.)
Sample space is
Ω = { ω1 , ω2 , . . . , ω8 }
= {HHH, HHT, HTH, HTT, THH, THT, TTH, TTT }.
and F be the event that exactly one pair of either heads or tails will
happen.
29 / 67
Tree diagrams
Start
1/2 1/2
H T 1st Toss
1/2 1/2 1/2 1/2
H T H T 2nd Toss
1/2 1/2 1/2 1/2 1/2 1/2 1/2 1/2
H T H T H T H T 3rd Toss
ω1 ω2 ω3 ω4 ω5 ω6 ω7 ω8 ← outputs
HHH HHT HTH HTT THH THT TTH TTT
30 / 67
Tree diagrams
Start
1/2 1/2
H T 1st Toss
1/2 1/2 1/2 1/2
H T H T 2nd Toss
1/2 1/2 1/2 1/2 1/2 1/2 1/2 1/2
H T H T H T H T 3rd Toss
ω1 ω2 ω3 ω4 ω5 ω6 ω7 ω8 ← outputs
HHH HHT HTH HTT THH THT TTH TTT
30 / 67
Tree diagrams
1
P(E) = P({TTT }) = m(TTT ) =
8
1 7
P(E) = 1 − P(E) = 1 − =
8 8
31 / 67
Tree diagrams
Example (Example contd.)
Let F be the event that either a pair of heads or a pair of tails turn up.
Let F1 be the event that exactly one pair of heads turns up,
Example (Contd.)
Need to compute the probability that either the first outcome is head
or the second outcome is a tail.
33 / 67
Tree diagrams
Start
1/2 1/2
H T 1st Toss
1/2 1/2 1/2 1/2
H T H T 2nd Toss
1/2 1/2 1/2 1/2 1/2 1/2 1/2 1/2
H T H T H T H T 3rd Toss
ω1 ω2 ω3 ω4 ω5 ω6 ω7 ω8 ← outputs
HHH HHT HTH HTT THH THT TTH TTT
34 / 67
Tree Diagrams
Example (Contd.)
Probability that either 1st outcome is head or 2nd outcome is tail.
Let A = {1st outcome is head} = {ω1 , ω2 , ω3 , ω4 },
and B = {2nd outcome is tail} = {ω3 , ω4 , ω7 , ω8 }.
By looking at the paths in the tree, we see that
1 1 1 1 1
P(A) = P(B) = + + + = ,
8 8 8 8 2
A ∩ B = { ω3 , ω4 } ,
1 1 1
P(A ∩ B) = + = ,
8 8 4
P(A ∪ B) = P(A) + P(B) − P(A ∩ B)
1 1 1 3
= + − =
2 2 4 4
35 / 67
Basic steps in solving discrete probability problems
36 / 67
Basic steps in solving discrete probability problems
36 / 67
Monty Hall Problem
What is the probability that a player who switches wins the car?
38 / 67
Monty Hall Problem
First objective is to identify all possible outcomes of the experiment.
For example, the Monty Hall game involves three such quantities:
For each possible location of the prize, the player could initially
choose any of the three doors. Represent this in a second layer added
to the tree.
Then a third layer represents the possibilities of the final step when
the host opens a door to reveal a goat.
39 / 67
MHP. Step1: Find sample space
40 / 67
MHP. Step 2: Define events of interest
41 / 67
MHP. Step 2: Define events of interest
The event that the player initially picked the door concealing the
prize is the set:
{(A, A, B), (A, A, C), (B, B, A), (B, B, C), (C, C, A), (C, C, B)}
The event that the player wins by switching is the set of outcomes:
{(A, B, C), (A, C, B), (B, A, C), (B, C, A), (C, A, B), (C, B, A)}
42 / 67
MHP. Step 2: Define events of interest
43 / 67
MHP. Step 3: Determine the outcomes probability
44 / 67
MHP. Step 3: Determine the outcomes probability
Next convert edge probabilities into outcome probabilities.
1 1 1 1
· · =
3 3 2 18
There’s an easy, intuitive justification for this rule. As the steps in an
experiment progress randomly along a path from the root of the tree
to a leaf, the probabilities on the edges indicate how likely the walk is
to proceed along each branch.
46 / 67
MHP. Step 4: Compute event probability
In contrast, a player who stays with his or her original door wins
with probability 13 , since staying wins if and only if switching loses.
47 / 67
Simulation of probability
Ω = { ω1 , ω2 , ω3 }
such that
1 1 1
m ( ω1 ) = , m ( ω2 ) = , m ( ω3 ) = .
2 3 6
If we have a die, such an event can be simulated by marking three
faces of a six-sided die with ω1 , two faces with ω2 and one face with
ω3 .
48 / 67
Simulation of probability
If you type
>> x=rand;
Then x will be a random number between 0 and 1.
>> x=rand(N);
returns an N × N matrix whose entries are random numbers from
[0, 1);
49 / 67
Simulation of probability
Example
>> rand(3,4)
0.2785 0.9649 0.9572 0.1419
0.5469 0.1576 0.4854 0.4218 ,
0.9575 0.9706 0.8003 0.9157 3×4
>> a=rand(1,6)
a = 0.7922 0.9595 0.6557 0.0357 0.8491 0.9340 1×6 ,
>> c=rand(3,1)
0.6787
c = 0.7577
0.7431 3×1
50 / 67
Simulation of probability
What if we need a random real number not in interval [0, 1], but in an
arbitrary interval [a, b]?
51 / 67
Simulation of probability
How about not a real number, but an integer?
Want to simulate tossing a die ⇒ need a random variable with values
from {1, 2, 3, 4, 5, 6}.
>> x=fix(6*rand)+1;
Indeed,
0≤r<1
0 ≤ 6r < 6
[6r] ∈ {0, 1, 2, 3, 4, 5}
[6r] + 1 ∈ {1, 2, 3, 4, 5, 6}
1
m(i) = , i = 1, 2, 3, 4, 5, 6.
6
52 / 67
Simulation of probability
Example (Contd)
Need to simulate an experiment with 3 possible outcomes:
Ω = { ω1 , ω2 , ω3 }
such that
1 1 1
m ( ω1 ) = , m ( ω2 ) = , m ( ω3 ) = .
2 3 6
Let x = [6r] + 1, with r ∈ [0, 1] a random number.
If x ∈ {1, 2, 3}, then ω1 has happened;
if x ∈ {4, 5}, then ω2 ;
if x ∈ {6}, then ω3 .
53 / 67
Simulation of probability
If r < 1/2 call the outcome heads (H); if not, call it tails (T). Another
way to proceed would be to ask the computer to pick a random
integer from set {0, 1}, and let H be 0, and T be 1.
HHHTTTHTTTTHTTTTTHTT.
Toss a coin n times, where n is much larger than 20, and see if the
proportion of heads is closer to intuitive guess of 1/2.
55 / 67
Heads or Tails Game
For example, the results of one particular game with 40 coin tosses is
HHTHTHHTTTTTHHHHTHTHTHTHHHHHTTHHHTHHTHHT
56 / 67
Heads or Tails Game
Heads or Tails Game. Petru’s winnings evolution graph
10
2
Winnings (banut)
−1
−2
−3
−4
−5
−6
−7
−8
−9
−10
0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40
Toss number
57 / 67
Heads or Tails Game
Heads or Tails Game. Petru’s winnings evolution graph
10
2
Winnings (banut)
−1
−2
−3
−4
−5
−6
−7
−8
−9
−10
0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40
Toss number
58 / 67
Heads or Tails Game
Heads or Tails Game. Petru’s winnings evolution graph
10
2
Winnings (banut)
−1
−2
−3
−4
−5
−6
−7
−8
−9
−10
0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40
Toss number
59 / 67
Heads or Tails Game
It is natural to ask for the probability that Petru will win j cents.
Let random variable W be defined as
Here, j could be any even number (Why even?) from −40 to 40.
It is natural to ask for the probability that Petru will win j cents.
Let random variable W be defined as
Here, j could be any even number (Why even?) from −40 to 40.
60 / 67
Heads or Tails Game
Simulate the game a large number of times and keep track of the
number of times that Petru’s final winnings are j.
The proportions over the number of games played give estimates for
the corresponding probabilities.
For example, if in 10000 games Petru has won 6 bănuţ 754 times, then
754
P(W = 6) ≈ = 0.0754.
10000
Count the number of times Petru has won j cents and plot these
results to get the distribution of probabilities.
61 / 67
Heads or Tails Game: 1000000 games
Distribution of winnings
0.14
0.13
0.12
0.11
0.1
0.09
Probability (winnings = j)
0.08
0.07
0.06
0.05
0.04
0.03
0.02
0.01
0
−40 −35 −30 −25 −20 −15 −10 −5 0 5 10 15 20 25 30 35 40
j
65 / 67
Heads or Tails Game
Such graphs we call bar graphs.
Note that the more games are played the ”smoother” will be the
resulting curve above the bars.
66 / 67
The End of Lecture
67 / 67
Mathematics for Computer Science
Lecture 16
1 / 69
Probability Joke
2 / 69
Uniform distribution
Definition
The uniform distribution on a sample space Ω containing n elements
is the function m defined by
1
m (ω ) =
n
for every ω ∈ Ω.
Example
Consider the experiment of tossing a coin twice. Sample space is
1
m(HH ) = m(HT ) = m(TH ) = m(TT ) = .
4
On the other hand, for some purposes, it may be more useful to
consider the 3−element sample space for the same experiment:
Ω1 = {0, 1, 2}
4 / 69
Uniform distribution
Example (Contd.)
The distribution function m1 on Ω1 defined by the equations:
1 1 1
m1 (0) = , m1 ( 1 ) = , m1 (2) =
4 2 4
corresponds to distribution m on Ω, but it is not uniform.
e on Ω1 :
Also, it is possible to choose another distribution function m
1
e (0) = m
m e (1) = m
e (2) = .
3
Although m e is a perfectly good uniform distribution function, it is
not consistent with observed data on coin tossing. So, it is not
appropriate for the considered experiment.
5 / 69
Uniform distribution
Example
Consider the experiment that consists of rolling a pair of dice.
Ω = {(i, j) | 1 ≤ i, j ≤ 6}
= {(1, 1), (1, 2), . . . , (2, 1), . . . , (5, 6), (6, 6)}
To determine the size of Ω, we note that there are six choices for i,
and for each choice of i there are six choices for j, leading to 36
different outcomes.
Assume that the dice are not loaded. In mathematical terms, this
means we adopt the uniform distribution function on Ω:
1
m((i, j)) = , 1 ≤ i, j ≤ 6
36
6 / 69
Uniform distribution
Example (Contd.)
Interested in answering the questions:
E = {(2, 6), (6, 2), (3, 5), (5, 3), (4, 4)}.
7 / 69
Uniform distribution
Example (Contd.)
Consequently, by definition of probability:
P(E) = ∑ m (ω )
ω ∈E
= m((2, 6)) + m((6, 2)) + m((3, 5)) + m((5, 3)) + m((4, 4))
1 5
= 5· =
36 36
P(F) = ∑ m ( ω )
ω ∈F
= m((5, 6)) + m((6, 5))
1 1
= 2· = .
36 18
8 / 69
Uniform distribution
Example (Contd.)
What is the probability of getting neither snakeeyes (double ones)
nor boxcars(double sixes)?
The event of getting either one of these two outcomes is the set
2 17
P(H ) = 1 − P(H ) = 1 − = .
36 18
9 / 69
Determination of probabilities
For example, in the case of the coin toss, there are no physical
difference between the two sides of a coin that can affect the chance
of one side or the other turning up.
10 / 69
Determination of probabilities
ATTENTION:
We should not always assume that, just because we do not know any
reason to suggest that one outcome is more likely than another, it is
appropriate to assign equal probabilities.
11 / 69
Infinite sample spaces
If a sample space Ω has an infinite number of points, then the way
that a distribution function is defined depends upon whether or not
the sample space is countable. If
Ω = {ω1 , ω2 , ω3 , . . . , ω2018 , . . .}
If the sample space is infinite but NOT COUTABLE (like R), then it is
a continuous probability case.
12 / 69
Infinite sample spaces
Indeed, if
Ω = { ω1 , ω2 , ω3 , . . . }
and uniform distribution is to be used:
m(wi ) = α, ∀i ∈ N,
∑ m( ω ) = 1
w∈ Ω
13 / 69
2nd Joke of the Day
14 / 69
3rd Joke
15 / 69
3rd Joke
15 / 69
4th Joke
16 / 69
Counting
Informal definiton
Combinatorics is the area of mathematics concerned with counting.
17 / 69
Counting. A little bit of history
Houses 7
Cats 49
Mice 343
Wheat 2401
Hekat 16807
19607
18 / 69
Counting. A little bit of history
An example of counting principle can be traced to at least 1730 in a
popular poem:
19 / 69
Memory quiz
Die Hard 3
20 / 69
Counting example
5692168374637019617423712 8176063831682536571306791
21 / 69
Counting seems easy
Just count: 1, 2, 3, 4, . . .
The explicit approach works well for counting simple things like
your fingers and for extremely complicated things for which there is
no identifiable structure.
22 / 69
Where counting is used?
23 / 69
Where counting is used: Algorithms
i.e., to put them in increasing (or decreasing) order: for. ex. input
4, 7, 6, 1, 3, 1, 9, 5 gives an output 1, 1, 3, 4, 5, 6, 7, 9.
24 / 69
Where counting is used: Graph theory
25 / 69
Where counting is used: Games
26 / 69
Where counting is used: Probability theory
27 / 69
Counting one thing by another
Therea are several rules for counting, most of them being intuitive.
How do you count people in a room?
For example, you can count the heads since for each person there is
exactly one head. Or you can count hands and divide by two. Just
recall the joke about a shepard in Transylvania and a reporter.
The general principle is that:
28 / 69
Mapping Rule
If you figure out the size of one set, then you can determine the sizes
of many other sets by bijections.
Example
Let
A = {all ways to choose 12 doughnuts from 5 available varieties:
chocolate, lemon, vanilla, raspberry and hazelnut}.
B = {all 16-bit sequences with exactly 4 ones}.
E.g: 0110001000001000, 1000100100000001, 0001001000100010.
29 / 69
Doughnuts example
Example (Contd.)
Consider a particular selection:
00
|{z} |{z} 000000
| {z } 00
|{z} 00
|{z}
chocolate lemon vanilla raspberry hazelnut
00
|{z} 1 |{z} 1 000000
| {z } 1 00
|{z} 1 00
|{z}
chocolate lemon vanilla raspberry hazelnut
We just formed a 16-bit sequence containing exactly 4 ones :
0011000000100100
There is a bijection from set A to set B: map 12 doughnuts
consisting of c chocolate, l lemon, v vanilla, r raspberry and h
hazelnut to the sequence 0| .{z. . 0}10| .{z
. . 0}10| .{z
. . 0}10| .{z
. . 0}10| .{z
. . 0}, a
c l v r h
sequence containing 16 bits and 4 ones.
By Mapping Rule we have |A| = |B| .
30 / 69
Sequences
Previous example and Mapping Rule suggest the following: learn to
count really well just few things and then use bijections to count
everything else.
sequence−counting
problems
S
bijection
A
all counting problems
31 / 69
Sequences vs Sets
Definition
A k−sequence is a sequence containing exactly k terms. A
2−sequence is also called a pair. A 3−sequence is called a triple. A
k−bit sequence is a k−sequence whose terms are bits, either 0 or 1.
32 / 69
Sum rule
Example
A good computer science student has 10 books on math, 35 books on
programming and 15 books on algorithms.
How many books does he/she have?
Let set M to be the set of math books, P be the set of prog books and
A be the set of books on algorithms. In these notations we are asked
to find |M ∪ P ∪ A|.
Definition
Let P1 , P2 , . . . , Pn be sets, then
P1 × P2 × . . . × Pn = {(p1 , p2 , . . . , pn ) | pi ∈ Pi }
34 / 69
Product rule
36 / 69
Putting rules together. Passwords
Example
On a computer system a valid password is a sequence of between 6
and 8 symbols. 1st symbol must be a letter (lowercase or uppercase),
remaining are either letters or digits. How many different passwords
are possible?
F = {a, b, . . . , z, A, B, . . . , Z}
S = {a, b, . . . , z, A, B, . . . , Z, 0, 1, . . . , 9}
F × S5 ∪ F × S6 ∪ F × S7
F × S5 ∪ F × S6 ∪ F × S7 = F × S5 + F × S6 + F × S7
38 / 69
Worst passwords in UK
39 / 69
Subsets of an n-element set
|Bn | = |B|n = 2n
40 / 69
The Pigeonhole Principle
Clearly, picking out three socks is not enough. You might end up
with one red, one green and one blue socks.
The solution of this and many other problems rely on the Dirichlet
Principle or Pigeonhole Principle, which is a consequence of the
Mapping Rule.
41 / 69
The Pigeonhole Principle. Too many pigeons
43 / 69
The Pigeonhole Principle
Let X be the set of socks and Y be the set of available colors.
X f
Y
fisrt sock
red
second sock
blue
fourth sock
The Pigeonhole Principle states that if |X| > |Y| = 3, then at least 2
elements of X must be mapped to the same element of Y.
44 / 69
Generalized Pigeonhole Principle
Generalized Pigeonhole Principle
If |X| > k · |Y| , then every function f : X → Y maps at least k + 1
different elements of X that are mapped to the same element of Y.
X f
Y
:
:
:
:
|X| |Y|
:
:
46 / 69
Counting example revisited
7820480135385502964448038 3171004832173501394113017 5763257331083479647409398 8247331000042995311646021
4894459918669156762409921 3208234421597368647019265 5800949123548989122628663 8496243997123475922766310
1082662032430379651370981 3437254656355157864869113 6042900801199280218026001 8518399140676002660747477
1178480894769706178994993 3574883393058653923711651 6116171789137737896701405 8543691283470191452333763
1253127351683239693851327 3644909946040480189969149 6144868973001582369735121 8675309258374137092461352
1301505129234077811069011 3790044132737084094417246 6247314593851169234746152 869432111236399686296665
1311567111143866433882194 3870332127437971355322815 6814428944266874963488274 8772321203608477245851154
1470029452721203876862144 4080505804577801451363100 6870852945543886849147881 8791422161722582546341091
1578271047286257499433886 4167283461025723481249203 6914955508120950093732397 9062628024592126283973285
1638243921852176243192354 4235996831123777788211249 6949632451369871524235413 9137845566925526349897794
1763580219131985963102365 4670939445749439042111220 7128211143613619828415650 915376296603189291934419
1826227795601842231029694 4815379351865384279613427 7173920083651862307925394 9270880194077636406984249
1843971826751020372014203 4837052948212922604442190 7215654874211755676220587 9324301480722103490379204
2396951193722134526177237 5106384238550185506715309 7256932847164391040233050 9436090832146695147140581
2781394568268599801096354 5142368192004769218069910 7332226570752354316203178 9475308159734538249013238
2796605196713610405408019 5181234096130144084041856 7426441829541573444964139 942376623917486974923202
2931016394761975263190347 5198267398125617994391348 7632198126531809327186321 9511972558779880288252979
9334580582944051551972967 5317592940316231219758372 7712154432211912882310511 9602413424619187112552264
3075514410490975920315344 5384358126771794128356947 7858918664240262356610010 9631217114906129219461111
3111474985252793452860017 5439211712248901995423417 7898156786763212963178679 9908189853102753335981319
3145621587936120118438701 5610379826092838192760458 8147591017037573337886166 9913237476341764299813987
3148901255628881103198549 5632317555465228677676044 8149436716871371161932035 315769310532511128321993
5692168374637019617423712 8176063831682536571306791
47 / 69
Counting example revisited
48 / 69
Binary Search
Here is a game: I think of an animal.
You can ask me 20 questions that take an yes/no answer such as:
”Does this animal have fur?”
”Is this animal eating people?”
etc
To win the game, you must ask a question like:
”Is the animal a fox?”
”Is this salmon?”
and receive the answer ”Yes”.
51 / 69
Binary Search
51 / 69
Binary Search
There are at most 524, 288 leaves, and 1, 000, 000 animals.
52 / 69
Weighing Coins
c1 c2 c3 c4 vs. c5 c6 c7 c8
< = >
< = >
c9 vs. c10
< = >
54 / 69
Weighing Coins
55 / 69
Weighing Coins
Since any of the 14 coins could be the counterfeited one, there are 28
possible situations.
So we have 28 pigeons.
The holes are the 27 leaves in any strategy ternary tree of depth 3.
Since there are more pigeons than holes, the Pigeonhole Principle
implies that some leaf is not associated to a unique situation.
56 / 69
Weighing Coins
Note that Pigeonhole Principle also implies that for 13 coins and 3
weighings a strategy may exist.
It does not exclude the case that the solution can fail to exist.
57 / 69
Basic strategy for counting
58 / 69
Generalized Product Rule
Consider a k−sequence:
Then,
|S| = n1 · n2 · n3 · . . . nk
59 / 69
UTM alphabet
60 / 69
”Defective” Lei
Need to compute
62 / 69
”Defective” Lei
For numerator, it is not allowed to use the same digit twice.
So, there are still 10 possibilities for the first digit, but only 9 for the
second digit, 8 for the third digit, an so forth.
By Generalized Product Rule there are
10 · 9 · 8 · 7 · 6 · 5 = 151, 200
non-defective lei is
151, 200
= 0.1512
1, 000, 000
and the probability of getting a defective lei is
63 / 69
A chess problem
K K
B
B P
P
64 / 69
A chess problem
Map this problem to a question about sequences:
rp , cp , rk , ck , rb , cb ,
rp , rk and rb are distinct rows, cp , ck and cb − distinct columns.
8 · 8 · 7 · 7 · 6 · 6 = 112, 896
66 / 69
Permutations
Definition
A permutation of a set S is a sequence that contains every element of
S exactly once.
For example, here are all permutations of the set {a, b, c}:
67 / 69
Permutations
n · (n − 1) · (n − 2) · . . . · 2 · 1 = n!
68 / 69
The End of Lecture
69 / 69