Lecture 27: Inclusion-exclusion Principle Dr. Chengjiang Long - - PowerPoint PPT Presentation

lecture 27 inclusion exclusion principle
SMART_READER_LITE
LIVE PREVIEW

Lecture 27: Inclusion-exclusion Principle Dr. Chengjiang Long - - PowerPoint PPT Presentation

Lecture 27: Inclusion-exclusion Principle Dr. Chengjiang Long Computer Vision Researcher at Kitware Inc. Adjunct Professor at SUNY at Albany. Email: clong2@albany.edu Announcement Our last class is Dec 10 th , 2018. Final Exam will be


slide-1
SLIDE 1

Lecture 27: Inclusion-exclusion Principle

  • Dr. Chengjiang Long

Computer Vision Researcher at Kitware Inc. Adjunct Professor at SUNY at Albany. Email: clong2@albany.edu

slide-2
SLIDE 2
  • C. Long

Lecture 27 November 6, 2018 2 ICEN/ICSI210 Discrete Structures

Announcement

  • Our last class is Dec 10th, 2018.
  • Final Exam will be taken on Dec 17th, 2018 (Monday).

q Two-hour exam from 3:30 pm to 5:30 pm at LC 25. q It will cover all the contents which we have talked in class. q Can be close book & close notes, or open book & open

notes.

slide-3
SLIDE 3
  • C. Long

Lecture 27 November 6, 2018 3 ICEN/ICSI210 Discrete Structures

Outline

  • Inclusion-exclusion Principle
  • Review on Modular Exponentiation Algorithm
slide-4
SLIDE 4
  • C. Long

Lecture 27 November 6, 2018 4 ICEN/ICSI210 Discrete Structures

Outline

  • Inclusion-exclusion Principle
  • Review on Modular Exponentiation Algorithm
slide-5
SLIDE 5
  • C. Long

Lecture 27 November 6, 2018 5 ICEN/ICSI210 Discrete Structures

If sets A and B are disjoint, then |A È B| = |A| + |B| A B What if A and B are not disjoint?

Sum Rule

slide-6
SLIDE 6
  • C. Long

Lecture 27 November 6, 2018 6 ICEN/ICSI210 Discrete Structures

For two arbitrary sets A and B

| | | | | | | | B A B A B A Ç

  • +

= È

A B

Inclusion-Exclusion (2 Sets)

slide-7
SLIDE 7
  • C. Long

Lecture 27 November 6, 2018 7 ICEN/ICSI210 Discrete Structures

A B C |A ∪ B ∪ C| = |A| + |B| + |C| – |A ∩ B| – |A ∩ C| – |B ∩ C| + |A ∩ B ∩ C|

Inclusion-Exclusion (3 Sets)

slide-8
SLIDE 8
  • C. Long

Lecture 27 November 6, 2018 8 ICEN/ICSI210 Discrete Structures

A B C

|A ∪ B ∪ C ∪ D| = |A| + |B| + |C| + |D| – |A ∩ B| – |A ∩ C| – |A ∩ D| – |B ∩ C| – |B ∩ D| – |C ∩ D| + |A ∩ B ∩ C| + |A ∩ B ∩ D| + |A ∩ C ∩ D| + |B ∩ C ∩ D| – |A ∩ B ∩ C ∩ D |

D

Inclusion-Exclusion (4 Sets)

slide-9
SLIDE 9
  • C. Long

Lecture 27 November 6, 2018 9 ICEN/ICSI210 Discrete Structures

What is the inclusion-exclusion formula for the union of n sets?

Inclusion-Exclusion (n Sets)

slide-10
SLIDE 10
  • C. Long

Lecture 27 November 6, 2018 10 ICEN/ICSI210 Discrete Structures

sum of sizes of all single sets – sum of sizes of all 2-set intersections + sum of sizes of all 3-set intersections – sum of sizes of all 4-set intersections … + (–1)n+1 sum of sizes of intersections of all n sets 1 2 n

A A A È È È =

{ }

1 1,2, , 1

( 1)

n k i S n k i S S k

A

+ Í = Î =

=

  • å

å

Inclusion-Exclusion (n Sets)

slide-11
SLIDE 11
  • C. Long

Lecture 27 November 6, 2018 11 ICEN/ICSI210 Discrete Structures

sum of sizes of all single sets – sum of sizes of all 2-set intersections + sum of sizes of all 3-set intersections – sum of sizes of all 4-set intersections … + (–1)n+1 sum of sizes of intersections of all n sets

|A1 ∪ A2 ∪ A3 ∪ … ∪ An|

We want to show that every element is counted exactly once. Consider an element which belongs to exactly k sets, say A1, A2, A3, …, Ak. In the formula, such an element is counted the following number of times: Therefore each element is counted exactly once, and thus the formula is correct

Inclusion-Exclusion (n Sets)

slide-12
SLIDE 12
  • C. Long

Lecture 27 November 6, 2018 12 ICEN/ICSI210 Discrete Structures

Plug in x=1 and y=-1 in the above binomial theorem, we have

Inclusion-Exclusion (n Sets)

slide-13
SLIDE 13
  • C. Long

Lecture 27 November 6, 2018 13 ICEN/ICSI210 Discrete Structures

In a Christmas party, everyone brings his/her present. There are n people and so there are totally n presents. Suppose the host collects and shuffles all the presents. Now everyone picks a random present. What is the probability that no one picks his/her own present? Let the n presents be {1, 2, 3, …, n}, where the present i is owned by person i. Now a random ordering of the presents means a permutation of {1, 2, 3, …, n}. e.g. (3,2,1) means the person 1 picks present 3, person 2 picks present 2, etc. And the question whether someone picks his/her own present becomes whether there is a number i which is in position i of the permutation.

Christmas Party

slide-14
SLIDE 14
  • C. Long

Lecture 27 November 6, 2018 14 ICEN/ICSI210 Discrete Structures

Given a random permutation of {1, 2, 3, …, n}, what is the probability that a permutation has no fixed point (i.e number i is not in position i for all i)? e.g. {2, 3, 1, 5, 6, 4} has no fixed point, {3, 4, 7, 5, 2, 6, 1} has a fixed point, {5, 4, 3, 2, 1} has a fixed point. You may wonder why we are suddenly asking a probability question. Actually, this is equivalent to the following counting question: What is the number of permutations of {1,2,3,…,n} with no fixed point?

Fixed Points in a Permutation

slide-15
SLIDE 15
  • C. Long

Lecture 27 November 6, 2018 15 ICEN/ICSI210 Discrete Structures

What is the number of permutations of {1,2,3,…,n} with no fixed point? Let S be the set of permutations of {1,2,3…,n} with some fixed point(s). For this question, it is more convenient to count the complement. Let A1 be the set of permutations in which the number 1 is in position 1. … Let Aj be the set of permutations in which the number j is in position j. … Let An be the set of permutations in which the number n is in position n. S = A1 ∪ A2 ∪ … ∪ An Note that Ai and Aj are not disjoint, and so we need inclusion-exclusion.

Fixed Points in a Permutation

slide-16
SLIDE 16
  • C. Long

Lecture 27 November 6, 2018 16 ICEN/ICSI210 Discrete Structures

Let S be the set of permutations of {1,2,3…,n} with some fixed point(s). Let Aj be the set of permutations in which the number j is in position j. S = A1 ∪ A2 ∪ … ∪ An How large is |Aj|? Once we fixed j, we can have any permutation on the remaining n-1 elements. Therefore, |Aj| = (n-1)! How large is |Ai ∩ Aj|? Once we fixed i and j, we can have any permutation on the remaining n-2 elements. Therefore, |Ai ∩ Aj| = (n-2)!

Fixed Points in a Permutation

slide-17
SLIDE 17
  • C. Long

Lecture 27 November 6, 2018 17 ICEN/ICSI210 Discrete Structures

Let S be the set of permutations of {1,2,3…,n} with some fixed point(s). Let Aj be the set of permutations in which the number j is in position j. S = A1 ∪ A2 ∪ … ∪ An How large is the intersection of k sets? In the intersection of k sets, there are k positions being fixed. Then we can have any permutation on the remaining n-k elements. Therefore, |the intersection of k sets| = (n-k)!

Fixed Points in a Permutation

slide-18
SLIDE 18
  • C. Long

Lecture 27 November 6, 2018 18 ICEN/ICSI210 Discrete Structures

Let S be the set of permutations of {1,2,3…,n} with some fixed point(s). Let Aj be the set of permutations in which the number j is in position j. S = A1 ∪ A2 ∪ … ∪ An |the intersection of k sets| = (n-k)!

sum of sizes of all single sets – sum of sizes of all 2-set intersections + sum of sizes of all 3-set intersections – sum of sizes of all 4-set intersections … + (–1)n+1 sum of sizes of intersections of n sets

|A1 ∪ A2 ∪ A3 ∪ … ∪ An|

|S| = |A1 ∪ A2 ∪ … ∪ An| …

Fixed Points in a Permutation

slide-19
SLIDE 19
  • C. Long

Lecture 27 November 6, 2018 19 ICEN/ICSI210 Discrete Structures

Let S be the set of permutations of {1,2,3…,n} with some fixed point(s). Let Aj be the set of permutations in which the number j is in position j. S = A1 ∪ A2 ∪ … ∪ An |the intersection of k sets| = (n-k)! |S| = |A1 ∪ A2 ∪ … ∪ An| … |S| = |A1 ∪ A2 ∪ … ∪ An| = n! – n!/2! + n!/3! +… (-1)i+1 n!/i! + … + (-1)n+1

Fixed Points in a Permutation

slide-20
SLIDE 20
  • C. Long

Lecture 27 November 6, 2018 20 ICEN/ICSI210 Discrete Structures

Let S be the set of permutations of {1,2,3…,n} with some fixed point(s). Let Aj be the set of permutations in which the number j is in position j. S = A1 ∪ A2 ∪ … ∪ An |S| = n! – n!/2! + n!/3! +… (-1)i+1 n!/i! + … + (-1)n+1 The number of permutations with no fixed points = n! – |S| = n! – n! + n!/2! – n!/3! +… (-1)i n!/i! + … + (-1)n = n! (1 – 1/1! + 1/2! – 1/3! + … + (-1)i 1/i! … + (-1)n 1/n!)

  • > n!/e (where e is the constant 2.71828…)

Fixed Points in a Permutation

slide-21
SLIDE 21
  • C. Long

Lecture 27 November 6, 2018 21 ICEN/ICSI210 Discrete Structures

Outline

  • Inclusion-exclusion Principle
  • Review on Modular Exponentiation Algorithm
slide-22
SLIDE 22
  • C. Long

Lecture 27 November 6, 2018 22 ICEN/ICSI210 Discrete Structures

Binary Modular Exponentiation

  • In general, to to compute bn we may use the binary

expansion of n, n = (ak-1,…,a1,ao)2 . Than

  • Therefore, to compute bn, we need only compute the

values of b, b2, (b2)2 = b4, (b4)2 = b8 , …, and the multiply the terms in this list, where aj = 1.

O((log m )2 log n) bit operations are used to find bn mod m.

slide-23
SLIDE 23
  • C. Long

Lecture 27 November 6, 2018 23 ICEN/ICSI210 Discrete Structures

Practice: 175235 mod 257

  • 235 = 128 + 64 + 32 + 8 + 2 + 1 = (11101011)2.
  • j

8 7 6 4 2 1 87654321

  • 175235 =175128 x17564 x17532 x1758 x1752 x175
  • d: records the temporal result, starting from the

rightmost factor.

  • t: represents the next term

where b = 175 in this example.

  • j = 1, 175 mod 257 = 175

1752 mod 257 = 42 d ß 175, t ß 42.

slide-24
SLIDE 24
  • C. Long

Lecture 27 November 6, 2018 24 ICEN/ICSI210 Discrete Structures

Practice: 175235 mod 257

  • 235 = 128 + 64 + 32 + 8 + 2 + 1 = (11101011)2.
  • j

8 7 6 4 2 1 87654321

  • 175235 =175128 x17564 x17532 x1758 x1752 x175
  • j = 2, 1752 x175 mod 257 = (1752 mod 257) x (175 mod

257) mod 257= t x d mod 257 = 42 x 175 mod 257 = 154

  • 1754 mod 257 = (1752 mod 257)2 mod 257
  • = t x t mod 257
  • = 42 x 42 mod 257 = 222
  • d ß 1752 x175 mod 257 = 154
  • t ß 1754 mod 257 = 222
slide-25
SLIDE 25
  • C. Long

Lecture 27 November 6, 2018 25 ICEN/ICSI210 Discrete Structures

Practice: 175235 mod 257

  • 235 = 128 + 64 + 32 + 8 + 2 + 1 = (11101011)2.
  • j

8 7 6 4 2 1 87654321

  • 175235 =175128 x17564 x17532 x1758 x1752 x175
  • j = 4, no factor 1754.
  • 1758 mod 257 = (1754 mod 257)2 mod 257
  • = t x t mod 257
  • = 222 x 222 mod 257 = 197
  • d ß 1752 x175 mod 257 = 154
  • t ß 1758 mod 257 = 197
slide-26
SLIDE 26
  • C. Long

Lecture 27 November 6, 2018 26 ICEN/ICSI210 Discrete Structures

Practice: 175235 mod 257

  • 235 = 128 + 64 + 32 + 8 + 2 + 1 = (11101011)2.
  • j

8 7 6 4 2 1 87654321

  • 175235 =175128 x17564 x17532 x1758 x1752 x175
  • j = 4, 1758 x1752 x175 mod 257 = (1758 mod 257) x

(1752 x175 mod 257) mod 257 = t x d mod 257 = 197 x 154 mod 257 = 12

  • 17516 mod 257 = (1758 mod 257)2 mod 257
  • = t x t mod 257
  • = 197 x 197 mod 257 = 2
  • d ß 1758 x1752 x175 mod 257 = 12
  • t ß 17516 mod 257 = 2
slide-27
SLIDE 27
  • C. Long

Lecture 27 November 6, 2018 27 ICEN/ICSI210 Discrete Structures

Practice: 175235 mod 257

  • 235 = 128 + 64 + 32 + 8 + 2 + 1 = (11101011)2.
  • j

8 7 6 4 2 1 87654321

  • 175235 =175128 x17564 x17532 x1758 x1752 x175
  • j = 5, no factor 17516
  • 17532 mod 257 = (17516 mod 257)2 mod 257
  • = t x t mod 257
  • = 2 x 2 mod 257 = 4
  • d ß 1758 x1752 x175 mod 257 = 12
  • t ß 17532 mod 257 = 14
slide-28
SLIDE 28
  • C. Long

Lecture 27 November 6, 2018 28 ICEN/ICSI210 Discrete Structures

Practice: 175235 mod 257

  • 235 = 128 + 64 + 32 + 8 + 2 + 1 = (11101011)2.
  • j

8 7 6 4 2 1 87654321

  • 175235 =175128 x17564 x17532 x1758 x1752 x175
  • j = 6, 17532x1758 x1752 x175 mod 257 = (17532 mod 257) x

(1758 x 1752 x175 mod 257) mod 257 = t x d mod 257 = 4 x 12 mod 257 = 48

  • 17564 mod 257 = (17532 mod 257)2 mod 257
  • = t x t mod 257
  • = 4 x 4 mod 257 = 16
  • d ß 17532x1758 x1752 x175 mod 257 = 48
  • t ß 17564 mod 257 = 16
slide-29
SLIDE 29
  • C. Long

Lecture 27 November 6, 2018 29 ICEN/ICSI210 Discrete Structures

Practice: 175235 mod 257

  • 235 = 128 + 64 + 32 + 8 + 2 + 1 = (11101011)2.
  • j

8 7 6 4 2 1 87654321

  • 175235 =175128 x17564 x17532 x1758 x1752 x175
  • j = 7, 17564 x17532x1758 x1752 x175 mod 257 = (17564 mod

257) x (17532x 1758 x 1752 x175 mod 257) mod 257 = t x d mod 257 = 16 x 48 mod 257 = 254

  • 175128 mod 257 = (17564 mod 257)2 mod 257
  • = t x t mod 257
  • = 16 x 16 mod 257 = 256
  • d ß 17564 x 17532x1758 x1752 x175 mod 257 = 48
  • t ß 175128 mod 257 = 256
slide-30
SLIDE 30
  • C. Long

Lecture 27 November 6, 2018 30 ICEN/ICSI210 Discrete Structures

Practice: 175235 mod 257

  • 235 = 128 + 64 + 32 + 8 + 2 + 1 = (11101011)2.
  • j

8 7 6 4 2 1 87654321

  • 175235 =175128 x17564 x17532 x1758 x1752 x175
  • j = 8, 175128 x 17564 x17532x1758 x1752 x175 mod 257 =

(175128 mod 257) x (17564 x 17532x 1758 x 1752 x175 mod 257) mod 257 = t x d mod 257 = 256 x 254 mod 257 =3

  • 175128 mod 257 = (17564 mod 257)2 mod 257
  • = t x t mod 257
  • = 16 x 16 mod 257 = 256
  • d ß 175128 x 17564 x 17532x1758 x1752 x175 mod 257 = 3
  • return d.
slide-31
SLIDE 31
  • C. Long

Lecture 27 November 6, 2018 31 ICEN/ICSI210 Discrete Structures

Analysis on d and t (1)

  • d = 175 mod 257
  • d = 1752 x175 mod 257
  • d = 1758 x1752 x175 mod 257
  • d = 17532x1758 x1752 x175 mod 257
  • d = 17564 x 17532x1758 x1752 x175 mod 257
  • d = 175128 x 17564 x 17532x1758 x1752 x175 mod 257

d = t x d mod 257 when t=175k and k=2j-1

slide-32
SLIDE 32
  • C. Long

Lecture 27 November 6, 2018 32 ICEN/ICSI210 Discrete Structures

Analysis on d and t (2)

  • t = 1752 mod 257 = 42
  • t = 1754 mod 257 = (1752 mod 257) 2 mod 257 = 222
  • t = 1758 mod 257 = (1754 mod 257) 2 mod 257 = 197
  • t = 17516 mod 257 = (1758 mod 257) 2 mod 257 = 2
  • t = 17532 mod 257 = (17516 mod 257) 2 mod 257 = 4
  • t = 17564 mod 257 = (17532 mod 257) 2 mod 257 = 16
  • t = 175128 mod 257 = (17564 mod 257) 2 mod 257 = 256

t = t2 mod 257

slide-33
SLIDE 33
  • C. Long

Lecture 27 November 6, 2018 33 ICEN/ICSI210 Discrete Structures

Practice: 175235 mod 257

  • 23510 = 111010112.
  • 1. d := 1 × 175 mod 257 = 175, t := 1752 mod 257 = 42;
  • 2. d := 175 × 42 mod 257 = 154, t := 422 mod 257 =

222;

  • 3. t := 2222 mod 257 = 197;
  • 4. d := 154 × 197 mod 257 = 12, t := 1972 mod 257 = 2;
  • 5. t := 22 mod 257 = 4;
  • 6. d := 12 × 4 mod 257 = 48, t := 42 mod 257 = 16;
  • 7. d := 48 × 16 mod 257 = 254, t := 162 mod 257 = 256;
  • 8. d := 254 × 256 mod 257 = 3
  • Return d = 3
slide-34
SLIDE 34
  • C. Long

Lecture 27 November 6, 2018 34 ICEN/ICSI210 Discrete Structures

Next class

  • Topic: Probability
  • Pre-class reading: Chap 7.1