Foundations of Computing II Lecture 4: Inclusion-exclusion principle - - PowerPoint PPT Presentation

foundations of computing ii
SMART_READER_LITE
LIVE PREVIEW

Foundations of Computing II Lecture 4: Inclusion-exclusion principle - - PowerPoint PPT Presentation

CSE 312 Foundations of Computing II Lecture 4: Inclusion-exclusion principle Stefano Tessaro tessaro@cs.washington.edu 1 Announcements Homework online tonight by 11:59pm. Go to sections tomorrow. 2 Inclusion-Exclusion Sometimes, we


slide-1
SLIDE 1

CSE 312

Foundations of Computing II

Lecture 4: Inclusion-exclusion principle

Stefano Tessaro

tessaro@cs.washington.edu

1

slide-2
SLIDE 2

Announcements

  • Homework online tonight by 11:59pm.
  • Go to sections tomorrow.

2

slide-3
SLIDE 3

Inclusion-Exclusion

3

Sometimes, we want ! , and ! = # ∪ % #

%

  • Fact. # ∪ % = # + % − |# ∩ %|
slide-4
SLIDE 4

Inclusion-Exclusion – Three Sets

4

# %

# ∪ % ∪ * ?

*

slide-5
SLIDE 5

Inclusion-Exclusion – Three Sets

5

# %

1 1 1 2 2 3 2

− # ∩ % − # ∩ * − |% ∩ *|

*

# + % + |C|

slide-6
SLIDE 6

Inclusion-Exclusion – Three Sets

6

# %

1 1 1 1 1 1

# + % + |C| − # ∩ % − # ∩ * − |% ∩ *|

*

+ # ∩ % ∩ *

slide-7
SLIDE 7

Inclusion-Exclusion – Three Sets

7

# %

1 1 1 1 1 1 1

# + % + |C| − # ∩ % − # ∩ * − |% ∩ *|

*

+ # ∩ % ∩ * # ∪ % ∪ * =

slide-8
SLIDE 8

Example – Number of Derangements

8

How many one-to-one maps -: 3 → 3 are there such that - 1 ≠ 1 for all 1?

1 1 2 2 3 3 1 1 2 2 3 3 1 1 2 2 3 3

slide-9
SLIDE 9

Example – Number of Derangements

9

How many one-to-one maps -: 3 → 3 are there such that - 1 ≠ 1 for all 1? Alternatively:

In how many ways can we arrange 3 people such that none

  • f them stays in place?

In how many ways can we have students grade each other’s homework without anyone grading their own homework?

slide-10
SLIDE 10

Example – Number of Derangements

10

How many one-to-one maps -: 3 → 3 are there such that - 1 ≠ 1 for all 1?

!5 = all one-to-one -: 3 → 3 # = all - ∈ !5 s.t. - 1 = 1 % = all - ∈ !5 s.t. - 2 = 2 * = all - ∈ !5 s.t. - 3 = 3

Wanted: !5 ∖ # ∪ % ∪ * = !5 − |# ∪ % ∪ *| = 3! =?

slide-11
SLIDE 11

Example – Number of Derangements

11

How many one-to-one maps -: 3 → 3 are there such that - 1 ≠ 1 for all 1?

!5 = all -: 3 → 3 # = all - ∈ !5 s.t. - 1 = 1 % = all - ∈ !5 s.t. - 2 = 2 * = all - ∈ !5 s.t. - 3 = 3

# + % + |C|− # ∩ % − # ∩ * − |% ∩ *| + # ∩ % ∩ * # ∪ % ∪ * =

= 2! = 2 = 1! = 1 = 0! = 1

slide-12
SLIDE 12

Example – Number of Derangements

12

How many one-to-one maps -: 3 → 3 are there such that - 1 ≠ 1 for all 1?

!5 = all -: 3 → 3 # = all - ∈ !5 s.t. - 1 = 1 % = all - ∈ !5 s.t. - 2 = 2 * = all - ∈ !5 s.t. - 3 = 3

3×2 − 3×1 + 1 = 4 # ∪ % ∪ * = !5 ∖ # ∪ % ∪ * = !5 − # ∪ % ∪ * = 3! − 4 = 2

slide-13
SLIDE 13

General Case – Number of Derangements

13

How many one-to-one maps -: < → < are there such that - 1 ≠ 1 for all 1 ∈ [<]?

We have seen that 1/3 permutations over [3] are derangements Any guesses for the general case? Vanishing fraction? Constant fraction?

slide-14
SLIDE 14
  • Theorem. For any <v(finite) sets #?, … , #B,

C

DE? B

#D = F

∅HI⊆[B]

−1

I K? L D∈I

#D

Inclusion-exclusion – General formula

14

sum over all subsets of [<], except the empty set + sign for odd-sized sets,

  • sign for even-sized sets
slide-15
SLIDE 15

Inclusion-exclusion – Proof (sketch)

15

Need to verify every element M ∈ ⋃DE?

B

#D is counted exactly once. Assume M is contained in 1 ≤ P ≤ < sets – call these #DQ, … , #DR In formula, M is counted P − P 2 + P 3 − P 4 + ⋯ = F

D TUU

P 1 − F

D VWVB,DXY

P 1 = 1

Why? Binomial theorem ⟹ 0 = 1 − 1 [ = ∑DEY

[

−1 D [

D

C

DE? B

#D = F

∅HI⊆[B]

−1

I K? L D∈I

#D

slide-16
SLIDE 16

Example – Number of Derangements

16

How many one-to-one maps -: < → < are there such that - 1 ≠ 1 for all 1 ∈ [<]?

!B = all one-to-one -: 3 → 3 #D = all - ∈ !B s.t. - 1 = 1

Wanted: !B ∖ #? ∪ #] ∪ ⋯ ∪ #B = !B − |#? ∪ #] ∪ ⋯ ∪ #B| = <! =?

  • Fact. ⋂D∈I #D = < − _ !
slide-17
SLIDE 17

17

C

DE? B

#D = F

∅HI⊆[B]

−1

I K? L D∈I

#D

  • Fact. ⋂D∈I #D = < − _ !

= F

∅HI⊆[B]

−1

I K? < − _ !

= F

[E? B

−1 [K? < P < − P ! = <! F

[E? B

−1 [K? P! = −<! F

[E? B

−1 [ P! !B ∖ C

DE? B

#D = <! − C

DE? B

#D = <! + <! F

[E? B

−1 [ P! = <! F

[EY B

−1 [ P!

→ <! `

[Indeed: result is integer closest to B!

V] < P = <! P! < − P ! `a = F

[EY b M[

P!

slide-18
SLIDE 18

Back to Euler’s Totient Function

18

  • Definition. The Euler totient function is defined as

c d = e ∈ [d] gcd e, d = 1} Goal: Give a formula for c d .

slide-19
SLIDE 19

19

#D = multiples of jD in [d]

  • Fact. ⋂D∈I #D =

k ∏m∈n om

Assume d = j

? VQj ] Vp … j [ VR where j ?, … , j[ are distinct primes (by the

fundamental theorem of arithmetic, this factorization is unique). |#D| = d/jD

We know (see last time): c d = [d] ∖ C

DE? [

#D = d − C

DE? [

#D

slide-20
SLIDE 20

20

c d = d − C

DE? [

#D = d − F

∅HI⊆[B]

−1

I K? L D∈I

#D

  • Fact. ⋂D∈I #D =

k ∏m∈n om

= d + F

∅HI⊆[B]

−1

I

d ∏D∈I jD = d F

I⊆[B]

−1

I

1 ∏D∈I jD = d F

I⊆[B]

−1

I r D∈I

1 jD

e.g. 1 − ?

  • Q

1 − ?

  • p = 1 − ?
  • Q − ?
  • p +

?

  • Qop

= d F

I⊆[B]

r

D∈I

− 1 jD = d r

DE? [

1 − 1 jD d = j

? VQj ] Vp … j [ VR

= r

DE? [

j

D Vms?(jD − 1)