Counting # possible passwords # possible keys

advertisement
Mathematics for Computer Science
Counting in Gambling
MIT 6.042J/18.062J
What fraction of poker hands
are “a pair of Jacks?”
J
10 J
66 10
22
Counting
JJ
Image by MIT OpenCourseWare.
(probability of a pair of Jacks)
Albert R Meyer,
April 9, 2010
lec 9F.1
Counting in Algorithms
April 9, 2010
# possible keys
lec 9F.5
Albert R Meyer,
April 9, 2010
lec 9F.6
The Sum Rule
•  Class has 43 women, 54 men so
total enrollment = 43 + 54 = 97
•  26 lower case letters, 26 upper
case letters, and 10 digits, so
# characters = 26+26+10 = 62
B
If sets A and B are
disjoint, then
|A B| = |A| + |B|
Albert R Meyer,
lec 9F.2
# possible passwords
Sum Rule
A
April 9, 2010
Counting in Cryptography
• # ops to update a data
structure (# comparisons
needed to sort n items)
• # steps in a computation (#
multiplies to compute dn)
Albert R Meyer,
Albert R Meyer,
April 9, 2010
lec 9F.8
Albert R Meyer,
April 9, 2010
lec 9F.9
1
The Product Rule
Product Rule
If |A| = m and |B| = n, then
|A × B| = mn
If there are 4 boys and 3
girls, there are
A = {a, b, c, d}, B = {1, 2, 3}
A × B = {(a,1),(a,2),(a,3),
4⋅3 = 12
different boy/girl couples
Albert R Meyer,
April 9, 2010
(b,1),(b,2),(b,3),
(c,1),(c,2),(c,3),
(d,1),(d,2),(d,3) }
lec 9F.10
Product Rule: Counting Strings
# length-4 binary strings
= |B4| where B ::= {0,1}
= 2 · 2 · 2 · 2 = 24
April 9, 2010
April 9, 2010
lec 9F.11
Product Rule: Counting Strings
# length n strings
from an alphabet of
size m is
mn
= |B × B × B × B|
Albert R Meyer,
Albert R Meyer,
lec 9F.12
Example: Counting Passwords
Albert R Meyer,
April 9, 2010
lec 9F.13
Counting Passwords
L ::= {a,b,…,z,A,B,…,Z}
D ::= {0,1,……,9}
Password conditions:
•  characters are digits & letters
•  between 6 & 8 characters long
•  starts with a letter
•  case sensitive
Pn ::= length n words
starting w/letter
= L × (L D)n-1
Albert R Meyer,
April 9, 2010
lec 9F.14
Albert R Meyer,
April 9, 2010
lec 9F.15
2
Counting Passwords
Counting Passwords
|L × (L D)n-1|
= |L|·|(L D)|n-1
= |L|·(|L| + |D|)n-1
= 52·(52+10)n-1
set of passwords:
Albert R Meyer,
April 9, 2010
P ::= P6 P7P8
|P| = |P6|+|P7|+|P8|
= 52·(625+626+627)
≈ 19·1014
lec 9F.16
# 4-digit nums w/ ≥ one 7
lec 9F.18
Mapping Rule: Bijections
= |B|
B
A
f
Albert R Meyer,
April 9, 2010
= |4-digit nums|
− |those w/ no 7|
= 104 − 94 = 3439
Albert R Meyer,
April 9, 2010
lec 9F.19
Counting Doughnut Selections
If f is a bijection from A to B,
then |A|
lec 9F.17
|4-digit nums w/ ≥ one 7|
x: any digit o: any digit ≠ 7
7xxx or o7xx or oo7x or ooo7
103 + 9·102 + 92·10 + 93
= 3439
April 9, 2010
April 9, 2010
at least one 7: another way
cases by 1st occurrence of 7:
Albert R Meyer,
Albert R Meyer,
From 5 kinds of doughnuts
select a dozen.
let A ::= all selections of
12 doughnuts
00
000000
(none)
00
00
chocolate lemon
lec 9F.20
sugar
Albert R Meyer,
April 9, 2010
glazed plain
lec 9F.24
3
Counting Doughnut Selections
Counting Doughnut Selections
B::= 16-bit words with four 1’s
B::= 16-bit words with four 1’s
00 1
00 1(none) 1 000000 1 00 100
Albert R Meyer,
April 9, 2010
1 000000 1 00100
(none)
lec 9F.26
Albert R Meyer,
April 9, 2010
lec 9F.27
Team Problems
Counting Doughnut Selections
B::= 16-bit words with four 1’s
Problems
1−4
0011000000100100
a bijection:
(none)
Albert R Meyer,
April 9, 2010
lec 9F.28
Albert R Meyer,
April 9, 2010
lec 9F.36
4
MIT OpenCourseWare
http://ocw.mit.edu
6.042J / 18.062J Mathematics for Computer Science
Spring 2010
For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.
Download