Foundations of Computer Science Lecture 13 Counting

Similar documents
CSE 191, Class Note 05: Counting Methods Computer Sci & Eng Dept SUNY Buffalo

Section 5.1 The Basics of Counting

Permutations & Combinations. Dr Patrick Chan. Multiplication / Addition Principle Inclusion-Exclusion Principle Permutation / Combination

Lecture Overview. 2 Permutations and Combinations. n(n 1) (n (k 1)) = n(n 1) (n k + 1) =

# fixed points of g. Tree to string. Repeatedly select the leaf with the smallest label, write down the label of its neighbour and remove the leaf.

Books Recommended for Further Reading

(ii) Two-permutations of {a, b, c}. Answer. (B) P (3, 3) = 3! (C) 3! = 6, and there are 6 items in (A). ... Answer.

Injections, Surjections, and the Pigeonhole Principle

Math 155 (Lecture 3)

3.1 Counting Principles

1 Counting and Stirling Numbers

Basic Counting. Periklis A. Papakonstantinou. York University

Intermediate Math Circles November 4, 2009 Counting II

UNIVERSITY OF NORTHERN COLORADO MATHEMATICS CONTEST. First Round For all Colorado Students Grades 7-12 November 3, 2007

Generating Functions. 1 Operations on generating functions

18th Bay Area Mathematical Olympiad. Problems and Solutions. February 23, 2016

REVIEW FOR CHAPTER 1

Permutations, Combinations, and the Binomial Theorem

Worksheet on Generating Functions

CIS Spring 2018 (instructor Val Tannen)

Lecture 14: Graph Entropy

LINEAR ALGEBRAIC GROUPS: LECTURE 6

Chapter 1 : Combinatorial Analysis

Combinatorics II. Combinatorics. Product Rule. Sum Rule II. Theorem (Product Rule) Theorem (Sum Rule)

Bertrand s Postulate

COMP 2804 Solutions Assignment 1

Let us consider the following problem to warm up towards a more general statement.

Homework 1 Solutions. The exercises are from Foundations of Mathematical Analysis by Richard Johnsonbaugh and W.E. Pfaffenberger.

Problem Set 2 Solutions

Tutorial F n F n 1

Homework 3. = k 1. Let S be a set of n elements, and let a, b, c be distinct elements of S. The number of k-subsets of S is

Combinatorially Thinking

Combinatorics and Newton s theorem

Solutions to Final Exam

The Random Walk For Dummies

Combinatorics I Introduction. Combinatorics. Combinatorics I Motivating Example. Combinations. Product Rule. Permutations. Theorem (Product Rule)

Lecture 4: Grassmannians, Finite and Affine Morphisms

Putnam Training Exercise Counting, Probability, Pigeonhole Principle (Answers)

( ) GENERATING FUNCTIONS

Chapter 7 COMBINATIONS AND PERMUTATIONS. where we have the specific formula for the binomial coefficients:

Machine Learning Theory Tübingen University, WS 2016/2017 Lecture 11

As stated by Laplace, Probability is common sense reduced to calculation.

COS 341 Discrete Mathematics. Exponential Generating Functions and Recurrence Relations

Joe Holbrook Memorial Math Competition

Pairs of disjoint q-element subsets far from each other

MT5821 Advanced Combinatorics

HOMEWORK 2 SOLUTIONS

Summer High School 2009 Aaron Bertram

ARRANGEMENTS IN A CIRCLE

ECEN 655: Advanced Channel Coding Spring Lecture 7 02/04/14. Belief propagation is exact on tree-structured factor graphs.

1 Summary: Binary and Logic

Name of the Student:

Math 778S Spectral Graph Theory Handout #3: Eigenvalues of Adjacency Matrix

Basic Combinatorics. Math 40210, Section 01 Spring Homework 7 due Monday, March 26

What is Probability?

Number Representation

Week 5-6: The Binomial Coefficients

Math 105 TOPICS IN MATHEMATICS REVIEW OF LECTURES VII. 7. Binomial formula. Three lectures ago ( in Review of Lectuires IV ), we have covered

Lecture 11: Pseudorandom functions

Lecture 2.5: Sequences

What is Probability?

(k) x n. n! tk = x a. (i) x p p! ti ) ( q 0. i 0. k A (i) n p

CS322: Network Analysis. Problem Set 2 - Fall 2009

International Contest-Game MATH KANGAROO Canada, Grade 11 and 12

14 Classic Counting Problems in Combinatorics

NICK DUFRESNE. 1 1 p(x). To determine some formulas for the generating function of the Schröder numbers, r(x) = a(x) =

Complex Numbers Solutions

CS284A: Representations and Algorithms in Molecular Biology

We will conclude the chapter with the study a few methods and techniques which are useful

6.046 Recitation 5: Binary Search Trees Bill Thies, Fall 2004 Outline

= 5! 3! 2! = 5! 3! (5 3)!. In general, the number of different groups of r items out of n items (when the order is ignored) is given by n!

Math 475, Problem Set #12: Answers

Computability and computational complexity

Lecture 6 April 10. We now give two identities which are useful for simplifying sums of binomial coefficients.

ICS141: Discrete Mathematics for Computer Science I

MATH 324 Summer 2006 Elementary Number Theory Solutions to Assignment 2 Due: Thursday July 27, 2006

Discrete mathematics , Fall Instructor: prof. János Pach. 1 Counting problems and the inclusion-exclusion principle

Lecture 23 Rearrangement Inequality

CALCULATION OF FIBONACCI VECTORS

On Divisibility concerning Binomial Coefficients

SOLUTIONS TO PRISM PROBLEMS Junior Level 2014

Chapter 6. Advanced Counting Techniques

The Binomial Theorem

1. n! = n. tion. For example, (n+1)! working with factorials. = (n+1) n (n 1) 2 1

CSE 21 Mathematics for

Randomized Algorithms I, Spring 2018, Department of Computer Science, University of Helsinki Homework 1: Solutions (Discussed January 25, 2018)

Tennessee Department of Education

P1 Chapter 8 :: Binomial Expansion

Lecture Notes for CS 313H, Fall 2011

Lecture 16: Monotone Formula Lower Bounds via Graph Entropy. 2 Monotone Formula Lower Bounds via Graph Entropy

MA3210 Lecture 8: The Pigeonhole Principle I 1

Model Theory 2016, Exercises, Second batch, covering Weeks 5-7, with Solutions

Solutions to Final Exam Review Problems

( ) = p and P( i = b) = q.

Induction: Solutions

Chimica Inorganica 3

Permutations" Basic principle of counting" Tree diagrams" k = 3, n 1 = 2, n 2 = 3, n 3 = 2. Braille alphabet" 10/31/10

Some Basic Counting Techniques

Introduction To Discrete Mathematics

and each factor on the right is clearly greater than 1. which is a contradiction, so n must be prime.

Transcription:

Foudatios of Computer Sciece Lecture 3 Coutig Coutig Sequeces Build-Up Coutig Coutig Oe Set by Coutig Aother: Bijectio Permutatios ad Combiatios

Last Time Be careful of what you read i the media: sex i America. 2 Bipartite Graphs ad Matchig (Hall s Theorem). 3 Stable Marriage. 4 Coflict Graphs ad Colorig. Every tree is 2-colorable. 5 Other Graph Problems Coected compoets, spaig tree, Euler paths, etwork flow. ([easy]) Hamiltoia paths, K-ceter, vertex cover, domiatig set. ([hard]) Creator: Malik Magdo-Ismail Coutig: 2 / 7 Today

Today: Coutig Coutig sequeces. 2 Build-up coutig. 3 Coutig oe set by coutig aother: bijectio. 4 Permutatios ad combiatios. Creator: Malik Magdo-Ismail Coutig: 3 / 7 Objects We Ca Cout

Discrete Math Is About Objects We Ca Cout Three colors of cady:,,. A goody-bag has 3 cadies. How may goody-bags? (Oly the umber of each color matters: { } ad { } are the same goody-bag.) { } { } { } { } { } { } { } { } { } { } Challege Problems. What if there are 5 cadies per goody-bag ad 0 colors of cady? 2 Goody-bags come i bulk packs of 5. How may differet bulk packs are there? There are too may to list out. We eed tools! Creator: Malik Magdo-Ismail Coutig: 4 / 7 Sum Rule

Sum Rule How may biary sequeces of legth 3: {000, 00, 00, 0, 00, 0, 0, }. There are two types: those edig i 0 ad those edig i, {b b 2 b 3 } = {b b 2 0} {b b 2 } Sum Rule. N objects of two types: N of type- ad N 2 of type-2. The, N = N + N 2. {b b 2 b 3 } = {b b 2 0} + {b b 2 } (sum rule) = {b b 2 } 2 = ( {b 0} + {b } ) 2 (sum rule) = {b } 2 2 = 2 2 2 Creator: Malik Magdo-Ismail Coutig: 5 / 7 Product Rule

Product Rule {b b 2 b 3 } 2 2 2 Let N be the umber of choices for a sequece x x 2 x 3 x r x r. Let N be the umber of choices for x ; Let N 2 be the umber of choices for x 2 after you choose x ; Let N 3 be the umber of choices for x 3 after you choose x x 2 ; Let N 4 be the umber of choices for x 4 after you choose x x 2 x 3 ;. Let N r be the umber of choices for x r after you choose x x 2 x 3 x r. N = N N 2 N 3 N 4 N r. Example. There are 2 biary sequeces of legth : N = N 2 = = N = 2. The sum ad product rules are the oly basic tools we eed... plus TINKERING. Creator: Malik Magdo-Ismail Coutig: 6 / 7 Examples

Examples Meus. breakfast {pacake, waffle, Doritos} luch {burger, Doritos} dier {salad, steak, Doritos} {BLD} = 3 2 3 = 8. This works because: every complex object (meu) is a sequece BLD ad every sequece BLD is a uique complex object (meu). 2 NY plates. {ABC-234} = 26 26 26 0 0 0 0 = 26 3 0 4 76 millio. 3 Races. With 0 ruers, how may top-3 fiishes? {FST} = 0 9 8 = 720. 4 Passwords. Letter (a,...,z,a,...,z) followed by 5,6 or 7 letters or digits (0,...,9). 3 types: FS S 2 S 3 S 4 S 5 (or FS 5 for short); FS 6 ; ad, FS 7. (52 choices for F ad 62 for S.) {passwords} = {FS 5 } + {FS 6 } + {FS 7 } (sum rule) = 52 62 5 + 52 62 6 + 52 62 7 2 0 4 (product rule) ( millisecod to test a password 3 moths to break i usig 32,000 cores.) 5 Committees. 0 studets. How may ways to form a party plaig committee? Each studet ca be i or out of the committee: 2 2 2 = 2 0 = 024. {committees} = {0-bit biary strigs} e.g. {s s 2 s 3 s 4 s 5 s 6 s 7 s 8 s 9 s 0 } 0 0 0 0 0 0 {s, s 2, s 4, s 9 } 0 0 0 0 0 0 0 0 0 0 Creator: Malik Magdo-Ismail Coutig: 7 / 7 Examples from CS

Examples from CS Challege Exercises: A problem from the area of atural laguage processig (NLP). Wikipedia has 40 millio articles (6 millio i Eglish). You compute a edit distace betwee every pair of articles ad store this data i a 40millio 40millio array of 64-bit double precisio umbers. Estimate how much RAM you will eed to load this matrix ito memory. Ay suggestios o feasibly performig tasks usig this edit-distace data? (aswer: 3TB) A problem i schedulig exams. RPI has about 400 courses ad 5000 studets who iduce coflicts amog these courses for exam schedulig. Are 5 exam slots eough to schedule all the exams? You realize that you eed to color a 400-ode coflict graph usiig 5 colors. You ca geerate ad test validity of a 5-colorig at a rate of 3 millio per secod. Estimate how log it would take to determie that 5 exam slots is ot eough. (aswer: 0 456 years) Ay suggestios o what to do? Creator: Malik Magdo-Ismail Coutig: 8 / 7 Build-Up Coutig

Build-Up Coutig Number of biary sequeces of legth : 2. = umber biary sequeces of legth with exactly k s 0 k. k Legth-3 sequeces: 000 00 00 0 00 0 0 Legth-4 sequeces: 0000 000 000 00 000 00 00 0 000 00 00 0 00 0 0 Legth-5 sequeces: 00000 0000 0000 000 0000 000 000 00 0000 000 000 00 000 00 00 0 0000 000 000 00 000 00 00 0 000 00 00 0 00 0 0 ( ) k 0 2 3 4 5 6 7 8 k 0 2 3 4 5 6 7 8 Pascal s Triagle 2 3 3 4 6 4 5 0 0 5 6 5 20 5 6 7 2 35 35 2 7 8 28 56 70 56 28 8 {-sequece with k s} = 0 {( )-sequece with k s} }{{} ( k ) {( )-sequece with (k ) s} }{{} ( k ) k = + k (sum rule) base cases: = ; =. k 0 Creator: Malik Magdo-Ismail Coutig: 9 / 7 Goody Bags

Build-up Coutig for Goody Bags Q(, k) = umber of goody-bags of cadies with k colors Build-up coutig: there are ( + ) types of goody-bag. 0 2 3 Q(, k ) Q(, k ) Q( 2, k ) Q( 3, k ) Q(0, k ) Q(, k) = Q(0, k ) + Q(, k ) + + Q(, k ) (sum rule) Q(, k) 0 2 3 4 5 2 3 4 5 k 6 2 3 4 5 6 7 8 9 0 3 6 0 5 2 28 36 45 55 66 4 0 20 35 56 84 20 65 220 286 5 5 35 70 26 20 330 495 75 00 6 2 56 26 252 462 792 287 2002 3003 7 8 9 0 Q(, ) = ; Q(0, k) = Challege problems we had earlier. (5 cadies, 0 colors) 2002 goody-bags. 2 How may 5 goody-bag bulk packs (goody-bags have 3 cadies of 3 colors)? There are 0 types of goody-bag; 5 i a bulk pack. So we eed Q(5, 0) = 2002. Creator: Malik Magdo-Ismail Coutig: 0 / 7 Bijectio

Coutig Oe Set By Coutig Aother: Bijectio 0 goody-bags with 3 cadies of 3 colors. Ca label those goody bags usig {, 2,..., 0}. { } { } { } { } { } { } { } { } { } { } 2 3 4 5 6 7 8 9 0 -to- correspodece betwee goody-bags ad the set {, 2,..., 0}, a bijectio. A B A B A B A B ot a fuctio -to-; ot oto (ijectio, A ij B) A B oto; ot -to- (surjectio, A sur B) A B -to- ad oto (bijectio, A bij B) A = B A bij B implies A = B. Ca cout A by coutig B. Cout meus by coutig sequeces {BLD}. Works because Every sequece specifies a distict meu (-to- mappig). Every meu correspods to a sequece (the mappig is oto). Creator: Malik Magdo-Ismail Coutig: / 7 Goody Bags

Goody Bags Usig Bijectio to Biary Sequeces 3 colors,,,. Cosider the goody-bag {2, 3, 2 }: red cadies delimiter blue cadies delimiter gree cadies ifer color from positio goody-bags bij 9-bit biary sequeces with two s. Examples. 0000000000 {2, 3,,, 3 } 000000000 {0, 4, 0,, 4 } cadies ad k colors (k ) delimiters. umber of goody-bags with cadies of k colors = umber of ( + k )-bit sequeces with (k ) s Q(, k) = + k. k ( k ) keeps poppig up but we do t have a formula for it. Creator: Malik Magdo-Ismail Coutig: 2 / 7 Kig-Quee Positios

Kig-Quee Positios o a Chessboard complex object kig-quee positio umber of positios sequece to recostruct it c3g4 umber of sequeces c K r K c Q r Q Every positio gives a sequece with r k r Q ad c K c Q Every such sequece is a uique valid positio. 0Z0Z0Z0Z 8 Z0Z0Z0Z0 7 0Z0Z0Z0Z 6 Z0Z0Z0Z0 5 0Z0Z0ZqZ 4 Z0J0Z0Z0 3 0Z0Z0Z0Z 2 Z0Z0Z0Z0 a b c d e f g h Cout sequeces with r k r Q ad c K c Q. 8 choices for c K ad r K ; after choosig c K, r K, there are oly 7 choices for c Q ad r Q. By the product rule, the umber of sequeces is 8 8 7 7 = 336. By bijectio coutig, umber of Kig-Quee positios is 336. Creator: Malik Magdo-Ismail Coutig: 3 / 7 Castle-Castle Positios

Castle-Castle Positios o a Chessboard complex object castle-castle positio sequece to recostruct it c3g4 umber of positios umber of sequeces c r c 2 r 2 Problem. c3g4 ad g4c3 are the same positio. positio two sequeces with r r 2 ad c c 2 Twice as may sequeces as positios! 0Z0Z0Z0Z 8 Z0Z0Z0Z0 7 0Z0Z0Z0Z 6 Z0Z0Z0Z0 5 0Z0Z0ZrZ 4 Z0s0Z0Z0 3 0Z0Z0Z0Z 2 Z0Z0Z0Z0 a b c d e f g h Multiplicity Rule. If each object i A correspods to k objects i B, the B = k A. 8 choices for c ad r ; after choosig c, r, there are oly 7 choices for c 2 ad r 2. By the product rule, the umber of sequeces is 8 8 7 7 = 336. By the multiplicity rule, umber of Castle-Castle positios is 336 = 568. 2 Creator: Malik Magdo-Ismail Coutig: 4 / 7 Permutatios ad Combiatios

Permutatios ad Combiatios S = {, 2, 3, 4}, the 2-orderigs are: { 2, 3, 4, 2, 2 3, 2 4, 3, 3 2, 3 4, 4, 4 2, 4 3} (permutatios) the 2-subsets are: { 2, 3, 4, 2 3, 2 4, 3 4} (combiatios) With elemets, by the product rule, the umber of k-orderigs is umber of k-orderigs = ( ) ( 2) ( (k )) = e.g. umber of top-3 fiishes i 0-perso race is 0 9 8 = 0!/7!.! ( k)!. Pick a k-subset ( ( ) k ways) ad reorder it i k! ways to get a k-orderig. umber of k-orderigs = umber of k-subsets k! product rule = ( k ) k! bijectio to sequeces with k s umber of k-subsets =! = k k!( k)! Exercise. How may 0-bit biary sequeces with four s? Creator: Malik Magdo-Ismail Coutig: 5 / 7 Biomial Theorem

Biomial Theorem: (x + y) = i= i x i y i (x + y) 3 = (x + y)(x + y)(x + y) = xxx + xxy + xyx + xyy + yxx + yxy + yyx + yyy = x 3 + 3x 2 y + 3xy 2 + y 3. (All legth-3 biary sequeces b b 2 b 3 where each b i {x, y}) (x + y) = x + (?)x y+ (?)x 2 y 2 + (?)x 3 y 3 + + (?)xy + y strigs with ( ) x s ( ) ( 2 strigs with strigs with strigs with ( 2) x s ( 3) x s x ) ( ( ) 3) = ( ) x + ( ) x y + ( ) 2 x 2 y 2 + ( 3 ) x 3 y 3 + + ( ) xy + ( ) 0 y Example. What is the coefficiet of x 7 i the expasio of ( x + 2x) 0 Need ( x) i (2) 0 i x 7, which implies i = 6. The x 7 term is ( ) 0 6 ( x) 6 (2x) 4 Coefficiet of x 7 is ( ) 0 6 2 4 = 3360. Creator: Malik Magdo-Ismail Coutig: 6 / 7 Geeral Approach to Coutig

Geeral Approach to Coutig Complex Objects To cout complex objects, give a sequece of istructios that ca be used to costruct a complex object. Every sequece of istructios gives a uique complex object. There is a sequece of istructios for every complex object. Cout the umber of possible sequeces of istructios, which equals the umber of complex objects. Creator: Malik Magdo-Ismail Coutig: 7 / 7