330 likes | 430 Views
-. +. Great Theoretical Ideas In Computer Science. To Exclude Or Not To Exclude?. Lecture 11. CS 15-251. How many integer solutions to the following equations?. The # of solutions to. The coefficient of x k in (1-x) -n =.
E N D
- + Great Theoretical Ideas In Computer Science To Exclude Or Not To Exclude? Lecture 11 CS 15-251
The # of solutions to The coefficient of xk in(1-x)-n =
A famous generating function and power series expansion from calculus:
Question:What is the coefficient of X20 in ? The number of integer solutions to:
A school has 100 students. 50 take French, 40 take Latin, and 20 take both. How many students take neither language? • How many positive integers less than 70 are relatively prime to 70? (70=257) • How many 7 card hands have at least one card of each suit?
100 – 70 = 30 F French students L Latin students |F|=50|L|=40 French Latin French AND Latin students: |FL|=20 French OR Latin students: |F|+|L|-|F L| = 50 + 40 – 20 = 70 |FL|= Neither language:
U universe of elements Lesson: |AB| = |A| + |B| - |AB| U B A
U A2 A1 A3 • How many positive integers less than 70 are relatively prime to 70? 70 = 257 U = [1..70] A1 integers in U divisible by 2 A2 integersin U divisible by 5 A3 integersin U divisible by 7 |A1| = 35 |A2| = 14 |A3|=10
U A2 A1 A3 Lesson: Let Sk be the sum of the sizes of All k-tuple intersections of the Ai’s.
U all 7 card hands A1 all hands with no hearts A2 all hands with no spades A3 all hands with no diamonds A4 all hands with no clubs • How many 7 card hands contain at least one card of each suit?
The Principle of Inclusion and Exclusion Let A1,A2,…,An be sets in a universe U. Let Sk denote the sum of size of all k-tuple intersections of Ai’s.
x gets counted times by S1 “ “ “ times by S2 “ “ “ times by S3 “ “ “ times by Sn The formula counts x 1 time. Let x A1 An be an element appearing in m of the Ai’s.
Immediate corollary: Each x in the union gets counted once by the formula so we are done.
How many different ways can 6 pirates divide 20 bars of gold? # of integral solutions to
A famous application of inclusion-exclusion is to calculate the number of DERANGEMENTS. A permutation of [1..n] is called a derangement if for every i, the Number i is not in the i’th position.
1 2 3 4 5 4 2 5 3 1 1 2 3 4 5 2 3 1 5 4 23154 is a derangement Examples: 42531 is not
Dn # of derangements of [1..n] Dn = ? Dn/n! = ? What is the probability that if n people randomly reach into a dark closet to retrieve their hats, no person will pick their own hat?
# of j-tuples # of permutations with j elements fixed Calculating Dn using Inclusion-Exclusion U = all n! permutations of [1..n] Ai= all permutations where i goes in position i
But the power series converges rapidly. nearest integer
So if we handed back homework in random order the probability that no student would get his/her own paper is about 1/e.
ONTO(k,n) = # of functions from a k-element set onto an n element set. U = all nk functions from [1..k] to [1..n] Ai = functions that miss element i the intersection of j of the Ai’s has (n-j)k functions
Lemma: [ ways to do this] There are nk functions from [1..k] to [1..n]. Each function is constructed by 3 choices: • Pick j, 1 j k • Pick j elements from range • Pick a function from 1..k onto those j elements [ ONTO(k , j) ways to do this]