Will Monroe June 28, with materials by Mehran Sahami and Chris Piech. Combinatorics

Similar documents
Permutations. Example 1. Lecture Notes #2 June 28, Will Monroe CS 109 Combinatorics

1 Permutations. Example 1. Lecture #2 Sept 26, Chris Piech CS 109 Combinatorics

1 Permutations. 1.1 Example 1. Lisa Yan CS 109 Combinatorics. Lecture Notes #2 June 27, 2018

Probability. Will Monroe Summer 2017 with materials by Mehran Sahami and Chris Piech

The Product Rule The Product Rule: A procedure can be broken down into a sequence of two tasks. There are n ways to do the first task and n

1. Counting. 2. Tree 3. Rules of Counting 4. Sample with/without replacement where order does/doesn t matter.

Lecture 14. What s to come? Probability. A bag contains:

Discrete Mathematics: Logic. Discrete Mathematics: Lecture 15: Counting

CS100: DISCRETE STRUCTURES. Lecture 8 Counting - CH6

Discrete Structures Lecture Permutations and Combinations

Measuring Angles. Measuring Angles. Measuring Angles. Measuring Angles D E G J I K. Use a protractor to measure Also, tell whether the angle is

Counting and Probability

Lecture 1. Permutations and combinations, Pascal s triangle, learning to count

CSE 312: Foundations of Computing II Quiz Section #2: Combinations, Counting Tricks (solutions)

Counting. Chapter 6. With Question/Answer Animations

Introductory Probability

CS70: Lecture Review. 2. Stars/Bars. 3. Balls in Bins. 4. Addition Rules. 5. Combinatorial Proofs. 6. Inclusion/Exclusion

In how many ways can we paint 6 rooms, choosing from 15 available colors? What if we want all rooms painted with different colors?

MAT104: Fundamentals of Mathematics II Summary of Counting Techniques and Probability. Preliminary Concepts, Formulas, and Terminology

Today s Topics. Next week: Conditional Probability

Theory of Probability - Brett Bernstein

Counting Subsets with Repetitions. ICS 6C Sandy Irani

SMS Dictionary. Solution hint. Input format. Output format. (Indian National Olympiad in Informatics, INOI, 2007)

2006 Canadian Computing Competition: Junior Division. Sponsor:

CISC-102 Fall 2017 Week 8

n! = n(n 1)(n 2) 3 2 1

2. Combinatorics: the systematic study of counting. The Basic Principle of Counting (BPC)

CPCS 222 Discrete Structures I Counting

Sec 5.1 The Basics of Counting

Permutations and Combinations

What is counting? (how many ways of doing things) how many possible ways to choose 4 people from 10?

Problem Set 2. Counting

With Question/Answer Animations. Chapter 6

Discrete Mathematics and Probability Theory Spring 2014 Anant Sahai Note 11

CSS 343 Data Structures, Algorithms, and Discrete Math II. Balanced Search Trees. Yusuf Pisan

DISCRETE STRUCTURES COUNTING

About Permutations and Combinations: Examples

Section Summary. Permutations Combinations Combinatorial Proofs

CSE 100: RED-BLACK TREES

Mat 344F challenge set #2 Solutions

Topics to be covered

COMP 2804 solutions Assignment 4

SFRA45 QUICK MEASUREMENT GUIDE

Permutations and Combinations Section

RBT Operations. The basic algorithm for inserting a node into an RBT is:

Math 3012 Applied Combinatorics Lecture 2

MA/CSSE 473 Day 13. Student Questions. Permutation Generation. HW 6 due Monday, HW 7 next Thursday, Tuesday s exam. Permutation generation

CSCI 2200 Foundations of Computer Science (FoCS) Solutions for Homework 7

Self-Adjusting Binary Search Trees. Andrei Pârvu

Random Binary Search Trees. EECS 214, Fall 2017

Digital Design Laboratory Lecture 7. A/D and D/A

Compound Probability. Set Theory. Basic Definitions

Counting & Basic probabilities. Stat 430 Heike Hofmann

INDEX 1. GENERAL Know your scanner LCD Full Display...2

Combinatorics: The Fine Art of Counting

CS 237: Probability in Computing

Dynatel 965DSP / 3M Far-End-Device Setup

CSE 312: Foundations of Computing II Quiz Section #1: Counting (solutions)

Module 3 Greedy Strategy

Sec$on Summary. Permutations Combinations Combinatorial Proofs

November 6, Chapter 8: Probability: The Mathematics of Chance

Lesson 9.1 Assignment

Permutations And Combinations Questions Answers

COUNTING TECHNIQUES. Prepared by Engr. JP Timola Reference: Discrete Math by Kenneth H. Rosen

Combinatorics and Intuitive Probability

Lecture 18 - Counting

LAMC Junior Circle February 3, Oleg Gleizer. Warm-up

Week 3 Classical Probability, Part I

With Question/Answer Animations. Chapter 6

Week 6: Advance applications of the PIE. 17 and 19 of October, 2018

Discrete mathematics

Elementary Combinatorics CE 311S

RFID Systems, an Introduction Sistemi Wireless, a.a. 2013/2014

In this section, we will learn to. 1. Use the Multiplication Principle for Events. Cheesecake Factory. Outback Steakhouse. P.F. Chang s.

Well, there are 6 possible pairs: AB, AC, AD, BC, BD, and CD. This is the binomial coefficient s job. The answer we want is abbreviated ( 4

ACTIVITY 6.7 Selecting and Rearranging Things

COCI 2008/2009 Contest #3, 13 th December 2008 TASK PET KEMIJA CROSS MATRICA BST NAJKRACI

Chapter 7. Intro to Counting

CSE 312: Foundations of Computing II Quiz Section #1: Counting

5.3 Problem Solving With Combinations

STATISTICAL COUNTING TECHNIQUES

The study of probability is concerned with the likelihood of events occurring. Many situations can be analyzed using a simplified model of probability

ARTIFICIAL INTELLIGENCE (CS 370D)

Problem A. Worst Locations

Let s Get This Started!

Solutions Manual for the book Introduction to Probability by Joseph K. Blitzstein and Jessica Hwang c Chapman & Hall/CRC Press, 2015

A Note on Downup Permutations and Increasing Trees DAVID CALLAN. Department of Statistics. Medical Science Center University Ave

Module 3 Greedy Strategy

Permutations and Combinations

MA/CSSE 473 Day 14. Permutations wrap-up. Subset generation. (Horner s method) Permutations wrap up Generating subsets of a set

Today s Topics. Sometimes when counting a set, we count the same item more than once

aabb abab abba baab baba bbaa permutations of these. But, there is a lot of duplicity in this list, each distinct word (such as 6! 3!2!1!

Discrete Structures for Computer Science

Binary Continued! November 27, 2013

Jong C. Park Computer Science Division, KAIST

US A1 (19) United States (12) Patent Application Publication (10) Pub. No.: US 2014/ A1 Koh (43) Pub. Date: Nov.

Block 1 - Sets and Basic Combinatorics. Main Topics in Block 1:

Solutions to Problem Set 7

CSE 21 Practice Final Exam Winter 2016

Permutations and Combinations

Transcription:

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)