Tải bản đầy đủ (.pptx) (19 trang)

Discrrete mathematics for computer science counting

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (2.25 MB, 19 trang )

Counting

First Principles

3/22/19

1


Counting in Gambling

What fraction of poker hands
are “a pair of Jacks?”
(probability of a pair
of Jacks)

3/22/19

2


Counting in Algorithms

# ops to update a data
structure (# comparisons

needed to sort n

items)
# steps in a computation (#
n



multiplies to compute d )

3/22/19

3


Counting in Cryptography

# possible passwords
# possible keys

3/22/19
lec 10W.4


Sum Rule

A

B

If sets A and B are disjoint, then
|A ∪ B| = |A| + |B|

3/22/19

5



The Sum Rule



Class has 17 women, 25 men so
total enrollment = 17 + 25 = 42



26 lower case letters, 26 upper case letters, and 10 digits, so
# characters = 26+26+10 = 62

3/22/19
lec 10W.6


The Product Rule

If there are 4 men and 3
women, there are

4⋅3 = 12
different man/woman couples

3/22/19

7



Product Rule

If |A| = m and |B| = n, then
|A × B| = m⋅n
A = {a, b, c, d}, B = {1, 2, 3}
A × B = {(a,1),(a,2),(a,3),
(b,1),(b,2),(b,3),
(c,1),(c,2),(c,3),
(d,1),(d,2),(d,3) }
3/22/19

8


Product Rule: Counting Strings

# length-4 binary strings

= |B × B × B × B|
4

= |B | where B ::= {0,1}

=2·2·2·2=2

3/22/19

4

9



Product Rule: Counting Strings

# length n strings from an
alphabet of size m is

m
3/22/19

n
10


Example: Counting Passwords
Password conditions:






3/22/19

characters are digits & letters
between 6 & 8 characters long
starts with a letter
case sensitive

11



Counting Passwords

L ::= {a,b,…,z,A,B,…,Z}
D ::= {0,1,……,9}
Pn ::= length n words
starting w/letter

= L × (L ∪ D)
3/22/19

n-1
12


Counting Passwords

|L × (L ∪ D)

n-1

= |L|·|(L ∪ D)|

|

n-1

= |L|·(|L| + |D|)
= 52·(52+10)


3/22/19

n-1

n-1

13


Counting Passwords

set of passwords:

P ::= P6∪ P7∪P8
|P| = |P6|+|P7|+|P8|
5
6
7
= 52·(62 +62 +62 )
14
≈ 19·10

3/22/19

14


# 4-digit nums w/ ≥ one 7
cases by 1st occurrence of 7:


x: any digit o: any digit ≠ 7
7xxx or o7xx or oo7x or ooo7



103
2
+ 9·10

3/22/19

= 3439

2
3
+ 9 ·10 + 9

15


at least one 7: another way

|4-digit nums w/ ≥ one 7|

= |4-digit nums|
− |those w/ no 7|
=

3/22/19


104 − 94 = 3439

16


Cracking Passwords by Exhaustive Search



Suppose a password has to be a string of letters and digits beginning
with a letter




So there are 52∙62n-1 passwords of length n



How big does n have to be for it to take more than a day to try them
all?

Suppose a computer can try a password every billionth of a second
(one nanosecond per try)

3/22/19

17



More than a day:






n-1
9
52∙62
> number of nanoseconds in a day = 24∙60∙60∙10
n-1
12
62
> 1.66∙10
n-1 > log (1.66∙10

12
)/log 62 ≈ 6.8

So if passwords are at least 8 characters long it would take more
than a day to try them all by exhaustive search.

3/22/19

18


FINIS


3/22/19

19



×