COMPSCI 102 Discrete Mathematics for Computer Science.

Slides:



Advertisements
Similar presentations
Great Theoretical Ideas in Computer Science for Some.
Advertisements

Basic Permutations and Combinations
CompSci 102 Discrete Math for Computer Science March 27, 2012 Prof. Rodger Lecture adapted from Bruce Maggs/Lecture developed at Carnegie Mellon, primarily.
1 More Counting by Mapping Lecture 16: Nov 7. 2 This Lecture Division rule Catalan number.
Counting Chapter 6 With Question/Answer Animations.
Great Theoretical Ideas in Computer Science.
Counting III: Pascal’s Triangle, Polynomials, and Vector Programs Great Theoretical Ideas In Computer Science Steven RudichCS Spring 2003 Lecture.
Discrete Structures & Algorithms Counting Counting I: One-To-One Correspondence and Choice Trees.
Discrete Structures & Algorithms More Counting. + + ( ) + ( ) = ? Counting II: Recurring Problems and Correspondences.
CSE115/ENGR160 Discrete Mathematics 04/17/12
Counting II: Recurring Problems And Correspondences Great Theoretical Ideas In Computer Science Steven RudichCS Spring 2004 Lecture 10Feb 12, 2004Carnegie.
Counting I: One To One Correspondence and Choice Trees Great Theoretical Ideas In Computer Science Steven RudichCS Spring 2004 Lecture 9Feb 10,
Binomial Identities.
Lecture 5 Counting 4.3, Permutations r-permutation: An ordered arrangement of r elements of a set of n distinct elements. Example: S={1,2,3}:
More Counting Lecture 16: Nov 9 A B …… f. Counting Rule: Bijection If f is a bijection from A to B, then |A| = |B| A B …… f.
Counting II: Pascal, Binomials, and Other Tricks Great Theoretical Ideas In Computer Science A. Gupta D. Sleator CS Fall 2010 Lecture 8Sept. 16,
CompSci 102 Discrete Math for Computer Science March 22, 2012 Prof. Rodger Lecture adapted from Bruce Maggs/Lecture developed at Carnegie Mellon, primarily.
Fibonacci Numbers, Polynomial Coefficients, and Vector Programs.
More Counting Lecture 16: Nov 9 A B …… f. This Lecture We will study how to define mappings to count. There will be many examples shown. Bijection rule.
Lecture 11 Feb 17, 1998 Doug Beeferman Carnegie Mellon University Count your blessings... … faster !
Chapter 8. Section 8. 1 Section Summary Introduction Modeling with Recurrence Relations Fibonacci Numbers The Tower of Hanoi Counting Problems Algorithms.
Basic Counting Lecture 12: Oct 28. This Lecture We will study some basic rules for counting. Sum rule, product rule, generalized product rule Permutations,
Basic Counting. This Lecture We will study some basic rules for counting. Sum rule, product rule, generalized product rule Permutations, combinations.
Binomial Coefficients, Inclusion-exclusion principle
Chapter 6 With Question/Answer Animations 1. Chapter Summary The Basics of Counting The Pigeonhole Principle Permutations and Combinations Binomial Coefficients.
Permutations and Combinations
Fall 2002CMSC Discrete Structures1 One, two, three, we’re… Counting.
Great Theoretical Ideas in Computer Science.
Great Theoretical Ideas in Computer Science.
Counting III: Pascal’s Triangle, Polynomials, and Vector Programs Great Theoretical Ideas In Computer Science Steven RudichCS Spring 2003 Lecture.
Lecture 5 Counting 4.3, Permutations r-permutation: An ordered arrangement of r elements of a set of n distinct elements. Example: S={1,2,3}:
1 Binomial Coefficients CS 202 Epp, section ??? Aaron Bloomfield.
COMPSCI 102 Discrete Mathematics for Computer Science.
Discrete Mathematics for Computer Science. + + ( ) + ( ) = ? Counting II: Recurring Problems and Correspondences Chapter 9 slides 1-54.
Great Theoretical Ideas in Computer Science.
Fibonacci Numbers, Vector Programs and a new kind of science.
The Pigeonhole Principle. The pigeonhole principle Suppose a flock of pigeons fly into a set of pigeonholes to roost If there are more pigeons than pigeonholes,
Counting Discrete Mathematics. Basic Counting Principles Counting problems are of the following kind: “How many different 8-letter passwords are there?”
CompSci 102 Discrete Math for Computer Science March 20, 2012 Prof. Rodger Lecture adapted from Bruce Maggs/Lecture developed at Carnegie Mellon, primarily.
Counting II: Recurring Problems And Correspondences Great Theoretical Ideas In Computer Science John LaffertyCS Fall 2005 Lecture 7Sept 20, 2005Carnegie.
Counting I: One To One Correspondence and Choice Trees Great Theoretical Ideas In Computer Science Steven RudichCS Spring 2004 Lecture 9Feb 10,
Choose Your Representation! Great Theoretical Ideas In Computer Science Steven RudichCS Spring 2005 Lecture 14 Feb 24, 2005 Carnegie Mellon University.
1 CS 140 Discrete Mathematics Combinatorics And Review Notes.
Counting II: Recurring Problems And Correspondences Great Theoretical Ideas In Computer Science V. AdamchikCS Spring 2006 Lecture 6Feb 2, 2005Carnegie.
Binomial Coefficients: Selected Exercises
CS Lecture 8 Developing Your Counting Muscles.
2/24/20161 One, two, three, we’re… Counting. 2/24/20162 Basic Counting Principles Counting problems are of the following kind: “How many different 8-letter.
Counting I: One To One Correspondence and Choice Trees Great Theoretical Ideas In Computer Science John LaffertyCS Fall 2005 Lecture 6Sept 15,
Section 6.4. Powers of Binomial Expressions Definition: A binomial expression is the sum of two terms, such as x + y. (More generally, these terms can.
Binomial Coefficients and Identities
L14: Permutations, Combinations and Some Review EECS 203: Discrete Mathematics.
Polynomials Count! CS Lecture 9 X1 X1 X2 X2 + + X3 X3.
Counting III: Pigeonhole principal, Pascal’s Triangle and more Great Theoretical Ideas In Computer Science S. Rudich V. Adamchik CS Spring 2006.
Introduction to Discrete Mathematics
Developing Your Counting Muscles
CSE15 Discrete Mathematics 04/19/17
Generalized Permutations & Combinations: Selected Exercises
Counting III: Pascal’s Triangle, Polynomials, and Vector Programs
Great Theoretical Ideas in Computer Science
Basic Counting.
Great Theoretical Ideas in Computer Science
Counting Discrete Mathematics.
Basic Counting Lecture 9: Nov 5, 6.
Counting III: Pascal’s Triangle, Polynomials, and Vector Programs
Counting II: Recurring Problems And Correspondences
Great Theoretical Ideas in Computer Science
Discrete Mathematics for Computer Science
Introduction to Discrete Mathematics
Counting II: Recurring Problems And Correspondences
Presentation transcript:

COMPSCI 102 Discrete Mathematics for Computer Science

X1 X1 X2 X2 + + X3 X3 Lecture 8 Counting III

How many ways to rearrange the letters in the word ? How many ways to rearrange the letters in the word “SYSTEMS”?

SYSTEMS 7 places to put the Y, 6 places to put the T, 5 places to put the E, 4 places to put the M, and the S’s are forced 7 X 6 X 5 X 4 = 840

SYSTEMS Let’s pretend that the S’s are distinct: S 1 YS 2 TEMS 3 There are 7! permutations of S 1 YS 2 TEMS 3 But when we stop pretending we see that we have counted each arrangement of SYSTEMS 3! times, once for each of 3! rearrangements of S 1 S 2 S 3 7! 3! = 840

Arrange n symbols: r 1 of type 1, r 2 of type 2, …, r k of type k n r1r1 n-r 1 r2r2 … n - r 1 - r 2 - … - r k-1 rkrk (n-r 1 )! (n-r 1 -r 2 )!r 2 ! n! (n-r 1 )!r 1 ! = … = n! r 1 !r 2 ! … r k !

14! 2!3!2! = 3,632,428,800 CARNEGIEMELLON

Remember: The number of ways to arrange n symbols with r 1 of type 1, r 2 of type 2, …, r k of type k is: n! r 1 !r 2 ! … r k !

5 distinct pirates want to divide 20 identical, indivisible bars of gold. How many different ways can they divide up the loot?

Sequences with 20 G’s and 4 /’s GG/G//GGGGGGGGGGGGGGGGG/ represents the following division among the pirates: 2, 1, 0, 17, 0 In general, the ith pirate gets the number of G’s after the (i-1) st / and before the i th / This gives a correspondence (bijection) between divisions of the gold and sequences with 20 G’s and 4 /’s

Sequences with 20 G’s and 4 /’s How many different ways to divide up the loot? 24 4

How many different ways can n distinct pirates divide k identical, indivisible bars of gold? n + k - 1 n - 1 n + k - 1 k =

How many integer solutions to the following equations? x 1 + x 2 + x 3 + x 4 + x 5 = 20 x 1, x 2, x 3, x 4, x 5 ≥ 0 Think of x k are being the number of gold bars that are allotted to pirate k 24 4

How many integer solutions to the following equations? x 1 + x 2 + x 3 + … + x n = k x 1, x 2, x 3, …, x n ≥ 0 n + k - 1 n - 1 n + k - 1 k =

Identical/Distinct Dice Suppose that we roll seven dice How many different outcomes are there, if order matters? 6767 What if order doesn’t matter? (E.g., Yahtzee) 12 7 (Corresponds to 6 pirates and 7 bars of gold)

Multisets A multiset is a set of elements, each of which has a multiplicity The size of the multiset is the sum of the multiplicities of all the elements Example: {X, Y, Z} with m(X)=0 m(Y)=3, m(Z)=2 Unary visualization: {Y, Y, Y, Z, Z}

Counting Multisets = n + k - 1 n - 1 n + k - 1 k There number of ways to choose a multiset of size k from n types of elements is:

++ () + () = Polynomials Express Choices and Outcomes Products of Sum = Sums of Products

b2b2 b3b3 b1b1 t1t1 t2t2 t1t1 t2t2 t1t1 t2t2 b1t1b1t1 b1t2b1t2 b2t1b2t1 b2t2b2t2 b3t1b3t1 b3t2b3t2 (b 1 +b 2 +b 3 )(t 1 +t 2 ) = b1t1b1t1 b1t2b1t2 b2t1b2t1 b2t2b2t2 b3t1b3t1 b3t2b3t

There is a correspondence between paths in a choice tree and the cross terms of the product of polynomials!

1X1X1X1X 1X 1X 1X 1 X X X2X2 X X2X2 X2X2 X3X3 Choice Tree for Terms of (1+X) 3 Combine like terms to get 1 + 3X + 3X 2 + X 3

What is a Closed Form Expression For c k ? (1+X) n = c 0 + c 1 X + c 2 X 2 + … + c n X n (1+X)(1+X)(1+X)(1+X)…(1+X) After multiplying things out, but before combining like terms, we get 2 n cross terms, each corresponding to a path in the choice tree c k, the coefficient of X k, is the number of paths with exactly k X’s n k c k =

binomial expression Binomial Coefficients The Binomial Formula n 1 (1+X) n = n 0 X0X0 +X1X1 +…+ n n XnXn

The Binomial Formula (1+X) 0 = (1+X) 1 = (1+X) 2 = (1+X) 3 = (1+X) 4 = X 1 + 2X + 1X X + 3X 2 + 1X X + 6X 2 + 4X 3 + 1X 4

5! What is the coefficient of EMSTY in the expansion of (E + M + S + T + Y) 5 ?

What is the coefficient of EMS 3 TY in the expansion of (E + M + S + T + Y) 7 ? The number of ways to rearrange the letters in the word SYSTEMS

What is the coefficient of BA 3 N 2 in the expansion of (B + A + N) 6 ? The number of ways to rearrange the letters in the word BANANA

What is the coefficient of (X 1 r 1 X 2 r 2 …X k r k ) in the expansion of (X 1 +X 2 +X 3 +…+X k ) n ? n! r 1 !r 2 !...r k !

There is much, much more to be said about how polynomials encode counting questions!

Power Series Representation (1+X) n = n k XkXk  k = 0 n n k XkXk   = “Product form” or “Generating form” “Power Series” or “Taylor Series” Expansion For k>n, n k = 0

By playing these two representations against each other we obtain a new representation of a previous insight: (1+X) n = n k XkXk  k = 0 n Let x = 1, n k  k = 0 n 2 n = The number of subsets of an n-element set

By varying x, we can discover new identities: (1+X) n = n k XkXk  k = 0 n Let x = -1, n k  k = 0 n 0 = (-1) k Equivalently, n k  k even n n k  k odd n =

The number of subsets with even size is the same as the number of subsets with odd size

Proofs that work by manipulating algebraic forms are called “algebraic” arguments. Proofs that build a bijection are called “combinatorial” arguments (1+X) n = n k XkXk  k = 0 n

Let O n be the set of binary strings of length n with an odd number of ones. Let E n be the set of binary strings of length n with an even number of ones. We gave an algebraic proof that  O n  =  E n  n k  k even n n k  k odd n =

A Combinatorial Proof Let O n be the set of binary strings of length n with an odd number of ones Let E n be the set of binary strings of length n with an even number of ones A combinatorial proof must construct a bijection between O n and E n

An Attempt at a Bijection Let f n be the function that takes an n-bit string and flips all its bits f n is clearly a one-to- one and onto function...but do even n work? In f 6 we have for odd n. E.g. in f 7 we have:     Uh oh. Complementing maps evens to evens!

A Correspondence That Works for all n Let f n be the function that takes an n-bit string and flips only the first bit. For example,    

The binomial coefficients have so many representations that many fundamental mathematical identities emerge… (1+X) n = n k XkXk  k = 0 n

The Binomial Formula (1+X) 0 = (1+X) 1 = (1+X) 2 = (1+X) 3 = (1+X) 4 = X 1 + 2X + 1X X + 3X 2 + 1X X + 6X 2 + 4X 3 + 1X 4 Pascal’s Triangle: k th row are coefficients of (1+X) k Inductive definition of k th entry of n th row: Pascal(n,0) = Pascal (n,n) = 1; Pascal(n,k) = Pascal(n-1,k-1) + Pascal(n-1,k)

“Pascal’s Triangle” 0 0 = = = 1 Al-Karaji, Baghdad Chu Shin-Chieh 1303 Blaise Pascal = = = 1

Pascal’s Triangle “It is extraordinary how fertile in properties the triangle is. Everyone can try his hand”

Summing the Rows n k  k = 0 n 2 n = = 1 = 2 = 4 = 8 = 16 = 32 = 64

= Odds and Evens

Summing on 1 st Avenue  i = 1 n i 1 =  n i n+1 2 =

Summing on k th Avenue  i = k n i k n+1 k+1 =

Fibonacci Numbers = 2 = 3 = 5 = 8 = 13

Sums of Squares

Al-Karaji Squares +2  = 1 = 4 = 9 = 16 = 25 = 36

Pascal Mod 2

All these properties can be proved inductively and algebraically. We will give combinatorial proofs using the Manhattan block walking representation of binomial coefficients

How many shortest routes from A to B? B A 10 5

Manhattan j th streetk th avenue There areshortest routes from (0,0) to (j,k) j+k k

Manhattan Level nk th avenue There areshortest routes from (0,0) to (n-k,k) n k

Manhattan Level nk th avenue There are shortest routes from (0,0) to n k level n and k th avenue

Level nk th avenue

Level nk th avenue n k n-1 k-1 n-1 k = + +

Level nk th avenue n n n k  k = 0 n 2 =

Level nk th avenue n+1 k+1 i k  i = k n =

Vector Programs Let’s define a (parallel) programming language called VECTOR that operates on possibly infinite vectors of numbers. Each variable V ! can be thought of as:

Vector Programs Let k stand for a scalar constant will stand for the vector = V ! + T ! means to add the vectors position-wise + =

Vector Programs RIGHT(V ! ) means to shift every number in V ! one position to the right and to place a 0 in position 0 RIGHT( ) =

Vector Programs Example: V ! := ; V ! := RIGHT(V ! ) + ; V ! = Store: V ! =

Vector Programs Example: V ! := ; Loop n times V ! := V ! + RIGHT(V ! ); V ! = n th row of Pascal’s triangle Store: V ! =

X1 X1 X2 X2 + + X3 X3 Vector programs can be implemented by polynomials!

Programs  Polynomials The vector V ! = will be represented by the polynomial:  i = 0  aiXiaiXi P V =

Formal Power Series The vector V ! = will be represented by the formal power series:  i = 0  aiXiaiXi P V =

 i = 0  aiXiaiXi P V = V ! = is represented by 0 k V ! + T ! is represented by(P V + P T ) RIGHT(V ! ) is represented by(P V X)

Vector Programs Example: V ! := ; Loop n times V ! := V ! + RIGHT(V ! ); V ! = n th row of Pascal’s triangle P V := 1; P V := P V + P V X;

Vector Programs Example: V ! := ; Loop n times V ! := V ! + RIGHT(V ! ); V ! = n th row of Pascal’s triangle P V := 1; P V := P V (1+X);

Vector Programs Example: V ! := ; Loop n times V ! := V ! + RIGHT(V ! ); V ! = n th row of Pascal’s triangle P V = (1+ X) n

Polynomials count Binomial formula Combinatorial proofs of binomial identities Vector programs Here’s What You Need to Know…