16
Computer Science Division: CS301 Course CS301, Part: ALGORITHMIC COMBINATORICS I( 3 rd Year Students ) Prepared by: http://www.researchgate.net/profile/Ahmed_Abdel-Fattah Lecture #3 N.B. The Mid-Term Exam will be held on 08-NOV-2014 (and it includes this lecture) Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3 rd Year Students — Lecture #3 1 (of 16)

Lecture #3: Algorithmic Combinatorics I "#FOSCS301"

Embed Size (px)

DESCRIPTION

Lecture #3 for course CS301: "Algorithmic Combinatorics I" for 3rd year students with a computer science major, Faculty of Science, Ain Shams University, Academic Year WS2014/2015.

Citation preview

Page 1: Lecture #3: Algorithmic Combinatorics I "#FOSCS301"

Computer Science Division: CS301

Course CS301, Part:“ALGORITHMIC COMBINATORICS I”

( 3rd Year Students )

Prepared by:

http://www.researchgate.net/profile/Ahmed_Abdel-Fattah

Lecture #3N.B. The Mid-Term Exam will be held on 08-NOV-2014

(and it includes this lecture)

Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Lecture #3 1 (of 16)

Page 2: Lecture #3: Algorithmic Combinatorics I "#FOSCS301"

Computer Science Division: CS301

Selections with REPETITIONS:When an object can be chosen more than once.

Example: Unordered Pairs of Numbers

A domino is a rectangular piece whose top face is divided into 2 squares.Each of the squares contains between 0 (blank) and 6 dots.

How many di!erent domino faces are possible?

Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Lecture #3 2 (of 16)

Page 3: Lecture #3: Algorithmic Combinatorics I "#FOSCS301"

Computer Science Division: CS301

Theorem (Selections with Unlimited Repetitions:a)

a([Tucker, 2007, Theorem 2, Page 188])

The number of selections with repetition of r objects chosen fromn (distinct) types of objects is C (r + n ! 1, r).

Proof.

1 We use n-1 separators to separate the n types.

2 The r objects to be selected can be represented by r !’s.

n types, n-1 separators! "# $

!!#$!"

1st

%%%!!!!# $! "

2nd

%%% · · ·

%%%!!!# $! "

nth

3 The number of sequences with r !’s and n-1 separators is&r + (n ! 1)

r

'

Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Lecture #3 3 (of 16)

Page 4: Lecture #3: Algorithmic Combinatorics I "#FOSCS301"

Computer Science Division: CS301

Example: Unordered Pairs of Numbers

How many di!erent domino faces are possible?

We use the theorem to find the number of ways to construct an unorderedpair of 2 numbers (with doubles allowed) between 0 and 6. This means:

1 We need to select r = 2 numbers,

2 With possible repetition, and3 From n = 7 types of numbers.

" C (r + n ! 1, r) = C (2 + 7! 1, 2) = 8!2!!6! = 28

Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Lecture #3 4 (of 16)

Page 5: Lecture #3: Algorithmic Combinatorics I "#FOSCS301"

Computer Science Division: CS301

Example: Selling Doughnuts

How many ways are there to fill a box with a dozen doughnuts (i.e. 12pieces) chosen from 5 di!erent varieties with the requirement that atleast one doughnut of each variety is picked?

Procedure:

Pick one doughnut of each variety

(N.B. this gives a total of five doughnuts in 1 way!!!)

The remaining 7 doughnuts are selected with repetition

Therefore, apply the theorem:n = 5 (types of doughnuts)r = 7 (objects needed to be selected)

" C(r + n ! 1, r) =

!

117

"

= 330

Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Lecture #3 5 (of 16)

Page 6: Lecture #3: Algorithmic Combinatorics I "#FOSCS301"

Computer Science Division: CS301

Example: Constrained Collections

How many ways are there to pick a collection of exactly 10 balls from apile of red balls, blue balls, and green balls if there must be:

1 at least 5 red balls?

2 at most 5 green balls?

Solutions:

1 Simply:Pick 5 red balls (in one way)

Pick the remaining 5 balls arbitrarily in

!

5 + 3! 15

"

= 21 ways

2 Count the complementary set:!

10 + 3! 110

"

= 66 ways to pick 10 balls without restriction

!

4 + 3! 14

"

= 15 ways to pick a collection with " 6 green balls

Answer: 66! 15 = 51 ways (to get 10 balls with # 5 green balls)

Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Lecture #3 6 (of 16)

Page 7: Lecture #3: Algorithmic Combinatorics I "#FOSCS301"

Computer Science Division: CS301

DISTRIBUTIONS:The “Distribution” Process

Assigning (distinct/identical) objects to (distinct/identical) cells:(ordered/unordered) collections in containers?other constraints?

Generally equivalent to selection or arrangement (with repetition).

Usually broken into subcases.distribution of distinct objects corresponds to arrangements.distribution of identical objects corresponds to selections.

Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Lecture #3 7 (of 16)

Page 8: Lecture #3: Algorithmic Combinatorics I "#FOSCS301"

Computer Science Division: CS301

Distinct Objects " Distinct Containers

We have r distinct objects and n distinct cells

" Each object can go in n places

" Product rule: n # n# · · ·# n# $! "

r"times

= nr distributions

Identical Objects " Distinct Containers

We have r identical objects and n distinct cells

" We choose r cells from the n in C (n, r) ways

If repetition is allowed, " there are

&r + n ! 1

r

'

distributions

Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Lecture #3 8 (of 16)

Page 9: Lecture #3: Algorithmic Combinatorics I "#FOSCS301"

Computer Science Division: CS301

Example: Diplomats

1 How many ways are there to assign 100 di!erent diplomats to 5di!erent continents?

2 How many ways if 20 diplomats must be assigned to each continent?

Solution:

1 The model for distributions tells us that:1 the r distinct objects correspond to the 100 diplomats2 the n distinct boxes correspond to the 5 continents3 " assignment can be done in n

r = 5100 ways

2 When distributing r di!erent objects into n di!erent boxes:1 if ri objects must go in box i , for 1 # i # n then

there are P(r ; r1, . . . , rn) =r !

r1!$ . . .$ rn!

" P(r ; r1, . . . , rn) = P(100; 20, 20, 20, 20, 20) =100!(20!)5

Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Lecture #3 9 (of 16)

Page 10: Lecture #3: Algorithmic Combinatorics I "#FOSCS301"

Computer Science Division: CS301

Example: Candy Shop

How many ways are there to distribute 20 (identical) sticks of redlicorice and 15 (identical) sticks of black licorice among 5 children?

1 Distribute the 20 red sticks in C (20 + 5! 1, 20) = 10, 626 ways

2 Distribute the 15 black sticks in C (15 + 5! 1, 15) = 3, 876 ways.

3 The product gives the number of ways to distribute all the candy.

Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Lecture #3 10 (of 16)

Page 11: Lecture #3: Algorithmic Combinatorics I "#FOSCS301"

Computer Science Division: CS301

Constrained Collections: A General NoteTheorem (Constrained Collections:a)

a([Tucker, 2007, Example 4, Page 195])

The number of ways to distribute r identical objects into n distinctboxes with at least one object in each box is C (r ! 1, n ! 1).

Proof.

1 Put 1 object in each of the n boxes.

2 Distribute the r ! n (identical) objects in n (distinct) boxes in&(r ! n) + n! 1

(r ! n)

'

=

&r ! 1

(r ! 1)! (r ! n)

'

=

&r ! 1

n ! 1

'

ways.

Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Lecture #3 11 (of 16)

Page 12: Lecture #3: Algorithmic Combinatorics I "#FOSCS301"

Computer Science Division: CS301

Application: Solving (Integer) Equations

1 How many integer solutions are there to the equationx1 + x2 + x3 + x4 = 12, with xi $ 0.

2 How many solutions with xi > 0?3 How many solutions with x1 $ 2, x2 $ 2, x3 $ 4, x4 $ 0?

Integer solution means (ordered) integer values for the x ’s.This kind of problems is modeled as “selection with repetition”:

each xi represents the number of (identical) 1’s in box i

(or represents the number of chosen objects of type i)

1 Here, we have r = 12 ones, and n = 4 boxes.

" The number of solutions is C (12 + 4! 1, 12) =

&15

12

'

= 455.

2 Here, we first put an object in each box =% r= 12! 4 = 8, n = 4." The number of solutions is C (8 + 4! 1, 8) = C (11, 3) = 165.3 Here, we first put objects in box i (as constrained):

i.e. Put 2 in x1, 2 in x2, 4 in x3

" The number of solutions is C ((12! 2! 2! 4) + 4! 1, 6) = 35.

Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Lecture #3 12 (of 16)

Page 13: Lecture #3: Algorithmic Combinatorics I "#FOSCS301"

Computer Science Division: CS301

Take Home Messages:1 Always keep in mind “WHY” the number of selections with

repetition of r objects chosen from n (distinct) types ofobjects is

(r+n"1

r

)

.2 Distributions (Part I: distinct cells):

Case/Distribution of: distinct objects identical objects

“no repetition” P(n, r) C (n, r)“unlimited repetition” nr

(r+n"1

r

)

“restricted repetition” P(n; r1, . . . , rt) —3 Remember 3 equivalent forms for selection with repetition:

1 “selecting” r objects with repetition from n di!erent types2 “distributing” r similar objects into n di!erent boxes

3 “solving”n

#

i=1

xi = r (nonnegative integers)

Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Lecture #3 13 (of 16)

Page 14: Lecture #3: Algorithmic Combinatorics I "#FOSCS301"

Computer Science Division: CS301

Homework #3:Letters & Envelopes

We have 3 identical letters, and we want to placea them into 4 di!erentcolored envelopes: yellow, blue, red, and green.How many ways can the 3 letters be placed into the 4 envelopes?

a(N.B. It is only possible to introduce one letter into each di!erent envelope.)

Think:

Do we need(43

)

,(4+3"1

4

)

, or(3+4"1

3

)

ways?

Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Lecture #3 14 (of 16)

Page 15: Lecture #3: Algorithmic Combinatorics I "#FOSCS301"

Computer Science Division: CS301

Homework #3:Shirts & Children

In how many di!erent ways can 3 identical green shirts and 3 identicalred shirts be distributed among 6 children such that each child receives ashirt?

Think:

Are we “selecting” 3 children in C (6, 3) = 6!3! 3! = 20 ways?

Are we “arranging” 6 shirts in P(6; 3, 3) = 6!3! 3! = 20 ways?

Why/Why not?

Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Lecture #3 15 (of 16)

Page 16: Lecture #3: Algorithmic Combinatorics I "#FOSCS301"

Computer Science Division: CS301

References:Tucker, A. (2007).Applied combinatorics.Wiley, 5th edition.

Dr. Ahmed Ashry “Algorithmic Combinatorics I” for 3rd Year Students — Lecture #3 16 (of 16)