• No results found

Counting 1.pptx

N/A
N/A
Protected

Academic year: 2020

Share "Counting 1.pptx"

Copied!
23
0
0

Loading.... (view fulltext now)

Full text

(1)

Basic Counting Principles

(2)

Counting

Determining the number of elements of a finite

set

Example: Password is a word of length 5, 6 or

7 symbols that can be letters or digits. We

want to find the number of all possible

(3)

Counting Rules

Product Rule: Suppose that a procedure can be broken down into a sequence of two tasks. If

there are n1ways to do the first task and for each of these ways of doing the first task, there are n2 ways to do the second task, then there are n1n2 ways to do the procedure.

An extended version of the product rule is often useful. Suppose that a procedure is carried

out by performing the tasks T1, T2, . . . , Tm in sequence. If each task Ti , i = 1, 2, . . . , n, can be done in ni ways, regardless of how the previous tasks were done, then there are n1 · n2 · · · nm

(4)

Counting examples

The chairs in the room can be labeled as L DD (one letter and

two digits, what is the maximal number of chairs labeled in different way? We suppose alphabet with 26 letters

Answer: 26*10*10

There are 38 students in a class, and 38 chairs, how

many different seating arrangements are there if everyone shows up?

Answer: 38*37*36 … *3*2*1

How many different bit strings of length seven are there? Answer: 2*2*2*2*2*2*2= 27

(5)

Important cases of the Product Rule

Cartesian product

|A1  A2  …  An| = |A1||A2|. . . |An|

Subsets of a set S

|P(S)|= 2|S|

Strings of length n over

(6)

Counting Rules

Sum Rule: If there are n1 choices of an element from S1 and n2 choices of an element from S2 and S1 S2 is empty, then there are n1 + n2 choices of an element from S1 S2

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, where none of the set of ni ways of

doing the task is the same as any of the set of nj

ways, for all pairs i and j with 1 ≤ i < j m.

Then the number of ways to do the task is n1 + n2

(7)

Combination of counting principles

BASIC variable names of length at most 2

Variables can be one or two characters long

The first character must be a letter

The second character can be a letter or a digit

The keywords “TO”, “IF”, and “DO” are excluded

Two sets of variables:

a) one letter – 26 variables

b) two symbols - 26.(26+10) - 3 variables Together 26+ 26.(26+10) - 3 =959

(8)

Counting Functions

Suppose |S| = n, |T| = m

How many functions from S to T?

Answer : m

n

How many one-to-one functions from S to T?

Answer :

m.(m-1).(m-2). … .(m-n+1)

when

m

n

otherwise

0

.

(9)

Counting Passwords

 Passwords must be 4 to 6 characters long, and must contain at least one letter and at least one digit. (Case insensitive, no special characters)

3 types of passwords :

a) 4 symbols – passwords of all digits or letters should be excluded – 4(26+10) – 426 - 410

a) 4 symbols – passwords of all digits or letters should be excluded – 5(26+10) – 526 - 510

a) 4 symbols – passwords of all digits or letters should be excluded – 6(26+10) – 626 - 610

(10)

The Division Rule

 There are n/d ways to do a task if it can be done using a procedure 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.”

(11)

The Division Rule

 How many 2 element subsets can be chosen from the set A={a,b,c,d,e}?

Answer:(5.4)/2=10

 How many 3 element subsets can be chosen from the set A={a,b,c,d,e}?

(12)

Inclusion-Exclusion Principle

How many binary strings of length 9 start with

0 or end with 11?

|A

1

|=2

8

|A

2

|=2

7

|A

1



A

2

|=2

6

Answer: 2

8

+ 2

7

- 2

6

=256+128-64=320

(13)

Inclusion-Exclusion

How many numbers from 1 to 100 are

divisible by 5?

Answer: :

100/5

= 20

How many numbers from 1 to 100 are

divisible by 3?

Answer:

100/3

= 33

How many numbers from 1 to 100 are

divisible by 3 or 5?

(14)

Inclusion-Exclusion

A class of 40 students has 20 CS majors, 15

Math majors. 5 of these students are dual

majors. How many students in the class are

neither math, nor CS majors?

(15)

Generalized Inclusion Exclusion

Principle

|ABC|=|A|+|B|+|C|-|AB|-|AC|-|BC|+|ABC|

Example: How many numbers from 1 to 100 are not divisible by 2, 3 or 5.

(16)

.

Generalized Inclusion Exclusion

Principle

26 7 14 27 7 13 3 3

26 = 100 – (50 +33 +20) + (16 + 10 + 6) - 3 50

33

20

16 10

(17)

Pigeon Hole Principle

If k is a positive integer and k+1 or more

objects are placed into k boxes, then at least one box has two or more objects

If N objects are placed into k boxes, then there is at least one box containing at least

(18)

PHP Applications

 How many students should be in the class to

guarantee that at least two students receive the same score of midterm exam, if the midterm exam is

graded from 0 to 20? Answer: 22

 Prove that if you have 800 people, at least three share a common birthday.

(19)

Exercises

 A multiple-choice test contains 10 questions. There are four possible answers for each question.

 a) In how many ways can a student answer the questions on the test if the student answers every question?

 b) In how many ways can a student answer the

questions on the test if the student can leave answers blank?

(20)

Exercises

 How many bit strings of length ten both begin and end with a 1?

 How many bit strings are there of length six or less, not counting the empty string?

(21)

Exercises

 How many positive integers between 5 and 31 a) are divisible by 3? Which integers are these? b) are divisible by 4? Which integers are these?

(22)

Exercises

 How many positive integers less than 1000 a) are divisible by 7?

b) are divisible by 7 but not by 11? c) are divisible by both 7 and 11? d) are divisible by either 7 or 11?

e) are divisible by exactly one of 7 and 11? f ) are divisible by neither 7 nor 11?

(23)

Exercises

 A bowl contains 10 red balls and 10 blue balls. A woman selects balls at random without looking at them.

a) How many balls must she select to be sure of having at least three balls of the same color?

b) How many balls must she select to be sure of having at least three blue balls?

References

Related documents

On the other hand, the ECM model was developed specifically to address the implementation of enterprise content management applications that manage records and

According to the field survey 2005-2006, the study area exhibits an admixture of a variety of land uses of rural character. This area has been developed as spatial growth of

Teknik pengumpulan data melalui kuesioner yang digunakan dalam penelitian ini terdiri atas pertanyaan yang dibuat berdasarkan masing-masing variabel, yaitu variabel

By generalizing the intertemporal consumption dependence underlying addictive behavior our revealed prefer- ence characterization extends the life cycle model of Browning (1989) and

Don’t be afraid to politely refuse to divulge unnecessary info, like your account or Social Security numbers unless you initiated the contact and know with whom you’re dealing. #39

From the Bulgarian atrocities of 1876, to the anti-Jew- ish pogroms in Russia in 1881–82, to the massacres of Armenians in the Otto- man Empire in 1895–96, Tenniel adopted

In order to solve theses problems, first, new location reference system for the National Highways was introduced by installing kilometer posts which were designed to have

Many African Americans appealed for the community to turn inward and called for the use of self-defense if the white com- munity continued to use such