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

Similar documents
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

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

CS 237: Probability in Computing

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

CS100: DISCRETE STRUCTURES. Lecture 8 Counting - CH6

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

Section : Combinations and Permutations

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

Question 1: How do you count choices using the multiplication principle?

Chapter 7. Intro to Counting

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

Compound Probability. Set Theory. Basic Definitions

Finite Math - Fall 2016

Theory of Probability - Brett Bernstein

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

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

Discrete Mathematics and Probability Theory Spring 2014 Anant Sahai Note 11

Lecture 2: Sum rule, partition method, difference method, bijection method, product rules

Counting Things. Tom Davis March 17, 2006

Checkpoint Questions Due Monday, October 7 at 2:15 PM Remaining Questions Due Friday, October 11 at 2:15 PM

9.5 Counting Subsets of a Set: Combinations. Answers for Test Yourself

Discrete Structures Lecture Permutations and Combinations

CS1800: More Counting. Professor Kevin Gold

MAT3707. Tutorial letter 202/1/2017 DISCRETE MATHEMATICS: COMBINATORICS. Semester 1. Department of Mathematical Sciences MAT3707/202/1/2017

CSE 312 Midterm Exam May 7, 2014

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

7.4 Permutations and Combinations

Probability and Counting Techniques

Coding for Efficiency

CSC/MATA67 Tutorial, Week 12

Discrete mathematics

Math 3012 Applied Combinatorics Lecture 2

Math 3338: Probability (Fall 2006)

Combinatorics and Intuitive Probability

Section 6.1 #16. Question: What is the probability that a five-card poker hand contains a flush, that is, five cards of the same suit?

Solutions to Problem Set 7

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

Permutations and Combinations

Math 475, Problem Set #3: Solutions

There are three types of mathematicians. Those who can count and those who can t.

Topics to be covered

Counting Subsets with Repetitions. ICS 6C Sandy Irani

CISC-102 Fall 2017 Week 8

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

Reading 14 : Counting

CISC 1400 Discrete Structures

Combinatorics: The Fine Art of Counting

5. (1-25 M) How many ways can 4 women and 4 men be seated around a circular table so that no two women are seated next to each other.

Mat 344F challenge set #2 Solutions

Probability MAT230. Fall Discrete Mathematics. MAT230 (Discrete Math) Probability Fall / 37

ACTIVITY 6.7 Selecting and Rearranging Things

Introduction to Mathematical Reasoning, Saylor 111

Elementary Combinatorics

Sorting. Suppose behind each door (indicated below) there are numbers placed in a random order and I ask you to find the number 41.

CPCS 222 Discrete Structures I Counting

Permutations and Combinations

Discrete Structures for Computer Science

CS 237 Fall 2018, Homework SOLUTION

Permutations and Combinations

Case 1: If Denver is the first city visited, then the outcome looks like: ( D ).

Problem Set 2. Counting

Counting Problems for Group 2(Due by EOC Sep. 27)

Mixed Counting Problems

How Euler Did It. by Ed Sandifer. Derangements. September, 2004

Probability. Engr. Jeffrey T. Dellosa.

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

and 6.855J. Network Simplex Animations

Unit 9: Probability Assignments

CSE 312: Foundations of Computing II Quiz Section #2: Inclusion-Exclusion, Pigeonhole, Introduction to Probability (solutions)

Chapter 7: Sorting 7.1. Original

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

Problems from 9th edition of Probability and Statistical Inference by Hogg, Tanis and Zimmerman:

Dyck paths, standard Young tableaux, and pattern avoiding permutations

Sec 5.1 The Basics of Counting

CHAPTER 8 Additional Probability Topics

6.4 Permutations and Combinations

Sample Spaces, Events, Probability

Week 1: Probability models and counting

Self-Adjusting Binary Search Trees. Andrei Pârvu

NOTES ON SEPT 13-18, 2012

Divide & conquer. Which works better for multi-cores: insertion sort or merge sort? Why?

PRIORITY QUEUES AND HEAPS. Lecture 19 CS2110 Spring 2014

FOURTH LECTURE : SEPTEMBER 18, 2014

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

6.1 Basics of counting

CHAPTER 2 PROBABILITY. 2.1 Sample Space. 2.2 Events

Slide 1 Math 1520, Lecture 15

Counting Things Solutions

Week 3 Classical Probability, Part I

Combinatorics: The Fine Art of Counting

I. WHAT IS PROBABILITY?

DECISION TREE TUTORIAL

Counting and Probability

POKER (AN INTRODUCTION TO COUNTING)

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

Math 1111 Math Exam Study Guide

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

A Probability Work Sheet

STAT 3743: Probability and Statistics

Transcription:

Will Monroe CS 09 Combinatorics Lecture Notes # June 8, 07 Handout by Chris Piech, with examples by Mehran Sahami As we mentioned last class, the principles of counting are core to probability. Counting is like the foundation of a house (where the house is all the great things we will do later in CS09, such as machine learning. Houses are awesome. Foundations, on the other hand, are pretty much just concrete in a hole. But don t make a house without a foundation. It won t turn out well. Permutations Permutation Rule: A permutation is an ordered arrangement of n distinct objects. Those n objects can be permuted in n (n (n = n! ways. This changes slightly if you are permuting a subset of distinct objects, or if some of your objects are indistinct. We will handle those cases shortly! Example Part A: iphones have 4-digit passcodes. Suppose there are 4 smudges over 4 digits on the screen. How many distinct passcodes are possible? Solution: Since the order of digits in the code is important, we should use permutations. And since there are exactly four smudges we know that each number is distinct. Thus, we can plug in the permutation formula: = 4. Part B: What if there are smudges over digits on screen? Solution: One of digits is repeated, but we don t know which one. We can solve this by making three cases, one for each digit that could be repeated (each with the same number of permutations. Let A, B, C represent the digits, with C repeated twice. We can initially pretend the two C s are distinct. Then each case will have permutations: A B C C However, then we need to eliminate the double-counting of the permutations of the identical digits (one A, one B, and two C s:!!! Adding up the three cases for the different repeated digits gives!!! = = 6 Part C: What if there are smudges over digits on the screen?

Solution: There are two possibilities: digits used twice each, or digit used times, and other digit used once.!! + = 6 + ( 4 = 6 + 8 = 4!! Example Recall the definition of a binary search tree (BST, which is a binary tree that satisfies the following three properties for every node n in the tree:. n s value is greater than all the values in its left subtree.. n s value is less than all the values in its right subtree.. both n s left and right subtrees are binary search trees. Problem: How many possible binary search trees are there which contain the three values,, and, and have a degenerate structure (i.e., each node in the BST has at most one child? Solution: We start by considering the fact that the three values in the BST (,, and may have been inserted in any one of! (=6 orderings (permutations. For each of the! ways the values could have been ordered when being inserted into the BST, we can determine what the resulting structure would be and determine which of them are degenerate. Below we consider each possible ordering of the three values and the resulting BST structure.,,,,,,,,,,,, We see that there 4 degenerate BSTs here (the first two and last two. Permutations of Indistinct Objects Permutation of Indistinct Objects: Generally when there are n objects and n are the same (indistinguishable, n are the same,... and n r are the same, then there are distinct permutations of the objects. n! n!n!... n r!

Example Problem: How many distinct bit strings can be formed from three 0 s and two s? Solution: 5 total digits would give 5! permutations. But that is assuming the 0 s and s are distinguishable (to make that explicit, let s give each one a subscript. Here is a subset of the permutations. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 If identical digits are indistinguishable, then all the listed permutations are the same. For any given permutation, there are! ways of rearranging the 0 s and! ways of rearranging the s (resulting in indistinguishable strings. We have over-counted. Using the formula for permutations of indistinct objects, we can correct for the over-counting: Total = 5!!! = 60 6 = 0 = 0. Combinations Combinations: A combination is an unordered selection of r objects from a set of n objects. If all objects are distinct, then the number of ways of making the selection is: ( n! n r!(n r! = r This is often read as n choose r. Consider this general way to produce combinations: To select r unordered objects from a set of n objects, e.g., 7 choose,. First consider permutations of all n objects. There are n! ways to do that.. Then select the first r in the permutation. There is one way to do that.. Note that the order of r selected objects is irrelevant. There are r! ways to permute them. The selection remains unchanged. 4. Note that the order of (n r unselected objects is irrelevant. There are (n r! ways to permute them. The selection remains unchanged. n! Total = r! (n r! = ( ( n r = n n r e.g., 7!! = 5 which is the combinations formula.

4 Example 4 Problem: In the Hunger Games, how many ways are there of choosing villagers from district, which has a population of 8,000? Solution: This is a straightforward combinations problem. ( 8000 Example 5 Part A: How many ways are there to select books from a set of 6? =,996,000. Solution: If each of the books are distinct, then this is another straightforward combination problem. There are ( 6 = 6!!! = 0 ways. Part B: How many ways are there to select books if there are two books that should not both be chosen together (for example, don t choose both the 8th and 9th edition of the Ross textbook. Solution: This problem is easier to solve if we split it up into cases. Consider the following three different cases: Case : Select the 8th Ed. and other non-9th Ed.: There are ( 4 ways of doing so. Case : Select the 9th Ed. and other non-8th Ed.: There are ( 4 ways of doing so. Case ( : Select from the books that are neither the 8th nor the 8th edition: There are 4 ways of doing so. Using our old friend the Sum Rule of Counting, we can add the cases: Total = (4 + ( 4 = 6. Alternatively, we could have calculated all the ways of selecting books from 4, and then subtract the forbidden ones (i.e., the selections that break the constraint. Chris Piech calls this the Forbidden City method. Forbidden Case: Select 8th edition and 9th edition and other book. There are ( 4 ways of doing so (which equals 4. Total = All possibilities forbidden = 0 4 = 6. Two different ways to get the same right answer! Bucketing / Group Assignment You have probably heard about the dreaded balls and urns probability examples. What are those all about? They are for counting the many different ways that we can think of stuffing elements into containers. (It turns out that Jacob Bernoulli was into voting and ancient Rome. And in ancient Rome they used urns for ballot boxes. This bucketing or group assignment process is a useful metaphor for many counting problems.

5 Example 6 Problem: Say you want to put n distinguishable balls into r urns. (No! Wait! Don t say that! Okay, fine. No urns. Say we are going to put n strings into r buckets of a hash table where all outcomes are equally likely. How many possible ways are there of doing this? Solution: You can think of this as n independent experiments each with r outcomes. Using our friend the General Principle of Counting, this comes out to r n. Divider Method: A divider problem is one where you want to place n indistinguishable items into r containers. The divider method works by imagining that you are going to solve this problem by sorting two types of objects, your n original elements and (r dividers. Thus, you are permuting n + r objects, n of which are same (your elements and r of which are same (the dividers. Thus: Total ways = (n+r! n!(r! = ( ( n+r n = n+r. r Example 7 Part A: Say you are a startup incubator and you have $0 million to invest in 4 companies (in $ million increments. How many ways can you allocate this money? Solution: This is just like putting 0 balls into 4 urns. Using the Divider Method we get: Total ways = ( ( 0+4 0 = 0 = 86. Part B: What if you don t have to invest all $0 M? (The economy is tight, say, and you might want to save your money. Solution: Imagine that you have an extra company: yourself. Now you are investing $0 million in 5 companies. Thus, the answer is the same as putting 0 balls into 5 urns. Total ways = ( ( 0+5 0 = 4 0 = 00. Part C: What if you know you want to invest at least $ million in Company? Solution: There is one way to give $ million to Company. The number of ways of investing the remaining money is the same as putting 7 balls into 4 urns. Total ways = ( ( 7+4 7 = 0 7 = 0.