Will Monroe June 28, 27 with materials by Mehran Sahami and Chris Piech Combinatorics
Review: Course website https://cs9.stanford.edu/
Logistics: Problem Set 4 questions (#: tell me about yourself!) Due: Wednesday, July 5 (before class) Handwrite and scan Word / Google Doc /... LaTeX (see website for getting started!) EmojiOne
Logistics: Office hours For SCPD: Thursday afternoon also online (Hangouts)!
Logistics: Textbook (or not) Sheldon Ross A First Course in Probability 9th (or 8th) Edition Optional! Has lots of helpful examples. Suggested readings on website. Go up two floors for copies on reserve (Terman Engineering Library)
Review: Principle of Inclusion/Exclusion The total number of elements in two sets is the sum of the number of elements of each set, minus the number of elements in both sets. A B = A + B A B 3 4 3+4- = 6
Review: General principle of counting An experiment consisting of two or more separate parts has a number of outcomes equal to the product of the number of outcomes of each part. A A 2 A n = A i shapes: 4 colors: 3 i total: 4 3 = 2
Permutations The number of ways of ordering n distinguishable objects. n n! = 2 3... n= i i=
Example: Servicing computers 9 computers to be scheduled for maintenance. How many possible orders?
Example: Servicing computers 9 computers to be scheduled for maintenance. How many possible orders? Pick the first: 9 choices
Example: Servicing computers 9 computers to be scheduled for maintenance. How many possible orders? 9 Pick the second: 8 choices
Example: Servicing computers 9 computers to be scheduled for maintenance. How many possible orders? 9 8 Pick the third: 7 choices
Example: Servicing computers 9 computers to be scheduled for maintenance. How many possible orders? 9 8 7 6 5 4 3 2
Example: Servicing computers 9 computers to be scheduled for maintenance. How many possible orders? 9 8 7 6 5 4 3 9 8 7 6 5 4 3 2 = 362,88 9! 2
Example: Servicing computers 4 laptops, 3 tablets, 2 desktops. Same type have to be serviced together. How many possible orders?
Example: Servicing computers 4 laptops, 3 tablets, 2 desktops. Same type have to be serviced together. How many possible orders?
Example: Servicing computers 4 laptops, 3 tablets, 2 desktops. Same type have to be serviced together. How many possible orders? 4!
Example: Servicing computers 4 laptops, 3 tablets, 2 desktops. Same type have to be serviced together. How many possible orders? 4! 3!
Example: Servicing computers 4 laptops, 3 tablets, 2 desktops. Same type have to be serviced together. How many possible orders? 4! 3! 2!
Example: Servicing computers 4 laptops, 3 tablets, 2 desktops. Same type have to be serviced together. How many possible orders? 4! 3! 4! 3! 2! = 288 2!
Example: Servicing computers 4 laptops, 3 tablets, 2 desktops. Same type have to be serviced together. How many possible orders? 3! 4! 3! 4! 3! 2! 3! =,728 2!
Review: Binary search trees binary: Every node has at most two children. 2 4 3 5
Review: Binary search trees binary: Every node has at most two children. search: Root value is - greater than values in the left subtree - less than values in the right subtree 2 4 3 5
Degenerate binary search trees degenerate: Every node has at most one child. 6 5 4 2 3
Degenerate binary search trees degenerate: Every node has at most one child. 3 2 How many different BSTs containing the values, 2, and 3 are degenerate?
Degenerate binary search trees BSTs can be listed by order of insertion. How many possible orders for inserting, 2, and 3?
Degenerate binary search trees BSTs can be listed by order of insertion. How many possible orders for inserting, 2, and 3? 3! = 6, 2, 3, 3, 2 2,, 3 2, 3, 3,, 2 3, 2,
Degenerate binary search trees BSTs can be listed by order of insertion. How many possible orders for inserting, 2, and 3? 3! = 6, 2, 3, 3, 2 2,, 3 2, 3, 3,, 2 3, 2,
Degenerate binary search trees BSTs can be listed by order of insertion. How many possible orders for inserting, 2, and 3? 3! = 6, 2, 3 2, 3, 2 2,, 3 2, 3, 3,, 2 3, 2,
Degenerate binary search trees BSTs can be listed by order of insertion. How many possible orders for inserting, 2, and 3? 3! = 6, 2, 3, 3, 2 2 3 2,, 3 2, 3, 3,, 2 3, 2,
Degenerate binary search trees BSTs can be listed by order of insertion. How many possible orders for inserting, 2, and 3? 3! = 6, 2, 3, 3, 2 2 3 2,, 3 2, 3, 3,, 2 3, 2,
Degenerate binary search trees BSTs can be listed by order of insertion. How many possible orders for inserting, 2, and 3? 3! = 6, 2, 3, 3, 2 2 3 3 2,, 3 2, 3, 3,, 2 3, 2,
Degenerate binary search trees BSTs can be listed by order of insertion. How many possible orders for inserting, 2, and 3? 3! = 6, 2, 3, 3, 2 2 3 3 2 2,, 3 2, 3, 3,, 2 3, 2,
Degenerate binary search trees BSTs can be listed by order of insertion. How many possible orders for inserting, 2, and 3? 3! = 6, 2, 3, 3, 2 2 3 3 2 2,, 3 2, 3, 2 2 3 3,, 2 3, 2, 3 3 3 2 2
Degenerate binary search trees BSTs can be listed by order of insertion. How many possible orders for inserting, 2, and 3? 3! = 6, 2, 3, 3, 2 2 3 3 2,, 3 2, 3, 2 2 3 3,, 2 3, 2, 3 3 2 2 2 4 degenerate BSTs 3
Permutations The number of ways of ordering n distinguishable objects. n n! = 2 3... n= i i=
Permutations with indistinct elements The number of ways of ordering n. objects, where some groups are indistinguishable. ( n k, k 2,, k m ) n! = k! k 2! k m! k2 identical n k identical
Return of the binary strings How many distinct bit strings are there consisting of three 's and two 's?
Return of the binary strings How many distinct bit strings are there consisting of three 's and two 's? 5! = 2?
Return of the binary strings How many distinct bit strings are there consisting of three 's and two 's? 5! = 2
Return of the binary strings How many distinct bit strings are there consisting of three 's and two 's? 5! =
Return of the binary strings How many distinct bit strings are there consisting of three 's and two 's? 5! =
Return of the binary strings How many distinct bit strings are there consisting of three 's and two 's? 5! =
Return of the binary strings How many distinct bit strings are there consisting of three 's and two 's? 5! =
Return of the binary strings How many distinct bit strings are there consisting of three 's and two 's? 2! 5! =
Return of the binary strings How many distinct bit strings are there consisting of three 's and two 's? 2! 5! = 3!
Return of the binary strings How many distinct bit strings are there consisting of three 's and two 's? 2! 5! = 3! x
Return of the binary strings How many distinct bit strings are there consisting of three 's and two 's? 2! 5! = 3! x 5!=2! 3! x
Return of the binary strings How many distinct bit strings are there consisting of three 's and two 's? 2! = 3! x 5! 5! x= 2! 3!
Example: Servicing computers 4 laptops, 3 tablets, 2 desktops. Same type are indistinguishable. How many possible orders?
Example: Servicing computers 4 laptops, 3 tablets, 2 desktops. Same type are indistinguishable. How many possible orders? 9!
Example: Servicing computers 4 laptops, 3 tablets, 2 desktops. Same type are indistinguishable. How many possible orders? 4! 9!
Example: Servicing computers 4 laptops, 3 tablets, 2 desktops. Same type are indistinguishable. How many possible orders? 3! 4! 9!
Example: Servicing computers 4 laptops, 3 tablets, 2 desktops. Same type are indistinguishable. How many possible orders? 3! 4! 9! 2!
Example: Servicing computers 4 laptops, 3 tablets, 2 desktops. Same type are indistinguishable. How many possible orders? 3! 4! 9! 9! 9 = =,26 4,3,2 4! 3! 2! ( ) 2!
Example: Servicing computers 4 laptops, 3 tablets, 2 desktops. Same type are indistinguishable. How many possible orders? 3! 4! 9! 9 = 9! =,26 4,3,2 4! 3! 2! ( ) 2!
Example: Passcode guessing 4-digit passcode on a phone. How many possible codes? 4 2 3 ABC DEF 5 6 GHI JKL MNO 7 8 9 PQRS TUV WXYZ https://bit.ly/a2ki4g https://b.socrative.com/login/student/ Room: CS9SUMMER7
Example: Passcode guessing 4-digit passcode on a phone. How many possible codes? 4 2 3 ABC DEF 5 6 GHI JKL MNO 7 8 9 PQRS TUV 4 =, WXYZ https://bit.ly/a2ki4g https://b.socrative.com/login/student/ Room: CS9SUMMER7
Example: Passcode guessing 4 smudges on phone for a 4-digit passcode. How many possible codes? 4 2 3 ABC DEF 5 6 GHI JKL MNO 7 8 9 PQRS TUV WXYZ https://bit.ly/a2ki4g https://b.socrative.com/login/student/ Room: CS9SUMMER7
Example: Passcode guessing 4 smudges on phone for a 4-digit passcode. How many possible codes? 4 2 3 ABC DEF 5 6 GHI JKL MNO 7 8 9 PQRS TUV 4!=24 WXYZ https://bit.ly/a2ki4g https://b.socrative.com/login/student/ Room: CS9SUMMER7
Example: Passcode guessing 3 smudges on phone for a 4-digit passcode. How many possible codes? 4 2 3 ABC DEF 5 6 GHI JKL MNO 7 8 9 PQRS TUV WXYZ https://bit.ly/a2ki4g https://b.socrative.com/login/student/ Room: CS9SUMMER7
Example: Passcode guessing 3 smudges on phone for a 4-digit passcode. How many possible codes? 4 2 3 ABC DEF 5 6 3 smudges = (less, same, more) possibilities vs. 4 smudges? A) less B) same C) more GHI JKL MNO 7 8 9 PQRS TUV WXYZ https://bit.ly/a2ki4g https://b.socrative.com/login/student/ Room: CS9SUMMER7
Example: Passcode guessing 3 smudges on phone for a 4-digit passcode. How many possible codes? 4 2 3 ABC DEF 5 6 GHI JKL MNO 7 8 9 PQRS TUV WXYZ 4! 3 =2 2!!!
Example: Passcode guessing 3 smudges on phone for a 4-digit passcode. How many possible codes? 4 2 3 ABC DEF 5 6 GHI JKL MNO 7 8 9 PQRS TUV WXYZ 4! 3 =36 2!!!
Example: Passcode guessing 2 smudges on phone for a 4-digit passcode. How many possible codes? 4 2 3 ABC DEF 5 6 GHI JKL MNO 7 8 9 PQRS TUV WXYZ
Example: Passcode guessing 2 smudges on phone for a 4-digit passcode. How many possible codes? 4 2 3 ABC DEF 5 6 GHI JKL MNO 7 8 9 PQRS TUV WXYZ Two and two Three and one
Example: Passcode guessing 2 smudges on phone for a 4-digit passcode. How many possible codes? 4 2 3 ABC DEF 5 6 4! =6 2! 2! Three and one GHI JKL MNO 7 8 9 PQRS Two and two TUV WXYZ
Example: Passcode guessing 2 smudges on phone for a 4-digit passcode. How many possible codes? 4 2 3 ABC DEF 5 6 4! =6 2! 2! Three and one GHI JKL MNO 7 8 9 PQRS Two and two TUV WXYZ 2 4! =8 3!!
Example: Passcode guessing 2 smudges on phone for a 4-digit passcode. How many possible codes? 4 2 3 ABC DEF 5 6 GHI JKL MNO 7 8 9 PQRS TUV WXYZ Two and two 4! =6 2! 2! + Three and one 2 4! =8 3!! =4
Permutations with indistinct elements The number of ways of ordering n. objects, where some groups are indistinguishable. ( n k, k 2,, k m ) n! = k! k 2! k m! k2 identical n k identical
Break time!
Combinations The number of unique subsets of size k from a larger set of size n. (objects are distinguishable, unordered) n k () n! = k!(n k )! choose k n
Picking drink flavors 5 drink flavors. How many ways to pick 3?
Picking drink flavors 5 drink flavors. How many ways to pick 3? 5! 5 = 5! = 2 2!3! ()
Picking drink flavors 5 drink flavors. How many ways to pick 3? 5! 3! 2! 5! = 5 3! 2! 3,2 ( )
Return of the binary strings How many distinct bit strings are there consisting of three 's and two 's? 2! = 3! x 5! 5! x= = 5 2! 3! 2,3 ( )
Return of the binary strings How many distinct bit strings are there consisting of three 's and two 's? = How many subsets of positions in a five-bit string are possible for placing two 's? 5! x= = 5 2! 3! 2,3 ( )
Return of the binary strings How many distinct bit strings are there consisting of three 's and two 's? = How many subsets of positions in a five-bit string are possible for placing two 's? 5! 5 5 x= = = 2! 3! 2,3 2 ( ) ()
Return of the binary strings How many distinct bit strings are there consisting of three 's and two 's? = How many subsets of positions in a five-bit string are possible for placing three 's? 5! 5 5 x= = = 3! 2! 3,2 3 ( )()
Return of the binary strings How many distinct bit strings are there consisting of three 's and two 's? = How many subsets of positions in a five-bit string are possible for placing three 's? 5! 5 5 5 x= = = = 3! 2! 3,2 3 2 ( ) () ()
Binomial coefficient n k () n! = k!(n k )! choose k n
Combinations The number of unique subsets of size k from a larger set of size n. (objects are distinguishable, unordered) n k () n! = k!(n k )! choose k n
Bucketing The number of ways of assigning n distinguishable objects to a fixed set of k buckets or labels. k n n objects k buckets
String hashing m = 5 strings pacific cooler n = 3 buckets wild cherry mountain cooler sugar not sugar
String hashing m = 5 strings pacific cooler n = 3 buckets wild cherry 3 mountain cooler 3 3 sugar 3 not sugar 3 =3 5
Divider method The number of ways of assigning n indistinguishable objects to a fixed set of k buckets or labels. ( n+(k ) n ) n objects k buckets (k - dividers)
Indistinguishable drinks?
Indistinguishable drinks?
Indistinguishable drinks?
Indistinguishable drinks?
Indistinguishable drinks?
Indistinguishable drinks? 5 drinks 3 students 3 = 2 dividers
Indistinguishable drinks? 7 objects
Indistinguishable drinks? 5 drinks 7 objects
Indistinguishable drinks? 5 drinks 7 objects
Indistinguishable drinks? 5 drinks 7 objects
Indistinguishable drinks? 5 drinks 7 = 5+(3 ) =2 5 5 ()( ) 7 objects
Investing in startups million dollar bill image: Simon Davison
Investing in startups million dollar bill image: Simon Davison
Investing in startups million dollar bill image: Simon Davison
Investing in startups million dollar bill image: Simon Davison
Investing in startups million dollar bill image: Simon Davison
Investing in startups ( +3 =286 ) million dollar bill image: Simon Davison
Permutations The number of ways of ordering n distinguishable objects. n n! = 2 3... n= i i=
Permutations with indistinct elements The number of ways of ordering n. objects, where some groups are indistinguishable. ( n k, k 2,, k m ) n! = k! k 2! k m! k2 identical n k identical
Combinations The number of unique subsets of size k from a larger set of size n. (objects are distinguishable, unordered) n k () n! = k!(n k )! choose k n
Bucketing The number of ways of assigning n distinguishable objects to a fixed set of k buckets or labels. k n n objects k buckets
Divider method The number of ways of assigning n indistinguishable objects to a fixed set of k buckets or labels. ( n+(k ) n ) n objects k buckets (k - dividers)