Introduction. CS243: Discrete Structures. Combinatorics. Product Rule. Basic Counting Rules. Example 2. Example 1

Similar documents
CS228 - Basic Counting and the Pigeonhole Principle

Counting Pigeonhole principle

Counting. Andreas Klappenecker

Counting Product Rule

Discrete Structures Lecture The Basics of Counting

Counting: Basics. Rosen, Chapter 6.1

Counting. Rosen, Chapter 6 Walls and Mirrors, Chapter 3

Discrete Structures for Computer Science

Solution : a) C(18, 1)C(325, 1) = 5850 b) C(18, 1) + C(325, 1) = 343

Basic Counting Principles: The Product Rule

It is important that you show your work. There are 134 points available on this test.

Counting: Basics. A simple counting problem. Counting: the product rule. Relation to Cartesian products. Relation to Cartesian products

ELEC-270 Solutions to Assignment 5

Math 3336 Section 6.1 The Basics of Counting The Product Rule The Sum Rule The Subtraction Rule The Division Rule

Notes for Recitation 13

COUNTING AND PROBABILITY

Non-context-Free Languages. CS215, Lecture 5 c

Solutions to In Class Problems Week 9, Fri.

Discrete Mathematics Exam File Fall Exam #1

Math 55 - Spring Lecture notes # 14 - March 9 (Tuesday)

Table of Laplace Transforms

Announcements. CS243: Discrete Structures. Strong Induction and Recursively Defined Structures. Review. Example (review) Example (review), cont.

Equations and Problem Solving with Fractions. Variable. Expression. Equation. A variable is a letter used to represent a number.

Discrete mathematics , Fall Instructor: prof. János Pach

Array Dependence Analysis as Integer Constraints. Array Dependence Analysis Example. Array Dependence Analysis as Integer Constraints, cont

Chapter 3. Set Theory. 3.1 What is a Set?

Problem Set 7 Solutions

Some Surprising Patterns!

Midterm 2 Solutions. CS70 Discrete Mathematics and Probability Theory, Spring 2009

Ma/CS 6b Class 10: Ramsey Theory

MATH 22 MORE ABOUT FUNCTIONS. Lecture M: 10/14/2003. Form follows function. Louis Henri Sullivan

Math 187 Sample Test II Questions

Ma/CS 6b Class 12: Ramsey Theory

2.2 Set Operations. Introduction DEFINITION 1. EXAMPLE 1 The union of the sets {1, 3, 5} and {1, 2, 3} is the set {1, 2, 3, 5}; that is, EXAMPLE 2

CPSC 320: Intermediate Algorithm Design and Analysis. Tutorial: Week 3

Gulf Shores Middle School 7 th Grade Summer Math Packet Advanced Pre- - - AP Math Reetz

Computer Science 236 Fall Nov. 11, 2010

CS1800 Discrete Structures Fall 2016 Profs. Aslam, Gold, Ossowski, Pavlu, & Sprague December 16, CS1800 Discrete Structures Final

Treaps. 1 Binary Search Trees (BSTs) CSE341T/CSE549T 11/05/2014. Lecture 19

Counting Problems; and Recursion! CSCI 2824, Fall 2012!

Graph Theory Part Two

CS 3512, Spring Instructor: Doug Dunham. Textbook: James L. Hein, Discrete Structures, Logic, and Computability, 3rd Ed. Jones and Barlett, 2010

[Ch 6] Set Theory. 1. Basic Concepts and Definitions. 400 lecture note #4. 1) Basics

Common Core State Standards Mathematics (Subset K-5 Counting and Cardinality, Operations and Algebraic Thinking, Number and Operations in Base 10)

CS525 Winter 2012 \ Class Assignment #2 Preparation

following determine whether it is an element, subset or neither of A and

Math 25 and Maple 3 + 4;

1 Algorithm and Proof for Minimum Vertex Coloring

UNIT 2: RATIONAL EXPRESSIONS

Grade 6 Math Circles November 6 & Relations, Functions, and Morphisms

Rational Numbers CHAPTER Introduction

CPS 102: Discrete Mathematics. Quiz 3 Date: Wednesday November 30, Instructor: Bruce Maggs NAME: Prob # Score. Total 60

Discrete Structures. Fall Homework3

Computer Science Foundation Exam

CS1800 Discrete Structures Fall 2016 Profs. Aslam, Gold, Ossowski, Pavlu, & Sprague December 16, CS1800 Discrete Structures Final

6.001 Notes: Section 4.1

Counting. Chapter Basic Counting. The Sum Principle. We begin with an example that illustrates a fundamental principle.

Packet #6: Counting & Graph Theory. Applied Discrete Mathematics

Student Outcomes. Lesson Notes. Classwork. Discussion (4 minutes)

Algorithms Dr. Haim Levkowitz

What is Set? Set Theory. Notation. Venn Diagram

CS 3L (Clancy) Solutions and grading standards for exam 1

THE UNIVERSITY OF MANITOBA

arxiv: v2 [math.co] 13 Aug 2013

CS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation

LESSON 1: INTRODUCTION TO COUNTING

Problem One: A Quick Algebra Review

Framework for Design of Dynamic Programming Algorithms

Chapter 3 Data Representation

USA Mathematical Talent Search Round 2 Solutions Year 23 Academic Year

CSCI FOUNDATIONS OF COMPUTER SCIENCE

Integrated Math 1 Module 3 Honors Sequences and Series Ready, Set, Go! Homework

CS2500 Exam 2 Fall 2011

Prepared by Sa diyya Hendrickson. Package Summary

CH 21 CONSECUTIVE INTEGERS

Indicate the option which most accurately completes the sentence.

Line Graphs and Circulants

CSE 312 Foundations II. 2. Counting. Winter 2017 W.L. Ruzzo

The Inclusion-Exclusion Principle

Order from Chaos. University of Nebraska-Lincoln Discrete Mathematics Seminar

Theory of Integers. CS389L: Automated Logical Reasoning. Lecture 13: The Omega Test. Overview of Techniques. Geometric Description

SECTION 5.1. Sequences

Exam 1 February 3, 2015

BITWISE OPERATORS. There are a number of ways to manipulate binary values. Just as you can with

Name Geometry Intro to Stats. Find the mean, median, and mode of the data set. 1. 1,6,3,9,6,8,4,4,4. Mean = Median = Mode = 2.

Math 6 Midterm Review Solutions

Encryption à la Mod Name

An Introduction to Graph Theory

Program Verification & Testing; Review of Propositional Logic

1 Linear programming relaxation

Using Euler s Theorem

CS145 Final Examination

1.2 Adding Integers. Contents: Numbers on the Number Lines Adding Signed Numbers on the Number Line

Properties and Definitions

b) Describe a procedure visitors should follow to find a free parking space, when the space they are assigned is occupied.

Homework 3 Solutions

Databases -Normalization I. (GF Royle, N Spadaccini ) Databases - Normalization I 1 / 24

The Resolution Algorithm

9/19/12. Why Study Discrete Math? What is discrete? Sets (Rosen, Chapter 2) can be described by discrete math TOPICS

Edge Colorings of Complete Multipartite Graphs Forbidding Rainbow Cycles

Transcription:

Introduction CS243: Discrete Structures Combinatorics Işıl Dillig Consider a set of objects and a property of interest Often, we want to know how many of these objects have the desired property Example: How many possible passwords are there if a password must contain 6-8 characters? These kinds of problems arise frequently in computer science Combinatorics (counting) deals with these questions Işıl Dillig, CS243: Discrete Structures Combinatorics 1/35 Işıl Dillig, CS243: Discrete Structures Combinatorics 2/35 Basic Counting Rules Product Rule Counting problems can be hard useful to decompose Two basic very useful decomposition rules: 1. Product rule: useful when task decomposes into a sequence of independent tasks 2. Sum rule: decomposes task into a set of alternatives Suppose a task A can be decomposed into a sequence of two independent tasks B and C n 1 ways of doing B n 2 ways of doing C Product rule: Then, there are n 1 n 2 ways of doing A Işıl Dillig, CS243: Discrete Structures Combinatorics 3/35 Işıl Dillig, CS243: Discrete Structures Combinatorics 4/35 Example 1 Example 2 New company with 12 offices and 2 employees Kate and Jack How many ways to assign different offices to Kate and Jack? Decomposition: First assign office to Kate, then to Jack How many ways to assign office to Kate? How many ways to assign office to Jack? How many ways to assign offices to Kate and Jack? Chairs in auditorium labeled with a letter (A-Z) and an integer [1, 100]. Examples: D32, G4, Z99 Under this labeling scheme, what is the maximum number of chairs in auditorium if we want every chair to be labeled? Observe: Max # of labeled chairs = # of different labelings Same as How many different labelings for a chair? Decomposition: First assign letter, then integer to chair Işıl Dillig, CS243: Discrete Structures Combinatorics 5/35 Işıl Dillig, CS243: Discrete Structures Combinatorics 6/35 1

Example 2, cont. Extended Product Rule Chairs in auditorium labeled with a letter (A-Z) and an integer [1, 100]. How many different labels? How many ways to assign a letter? How many ways to assign digit? How many ways to assign label? We formulated product rule for decomposition into 2 tasks But generalizes to decomposition into any k tasks Suppose task A decomposes to sequence of tasks A 1,... A k If there are n 1 ways of doing A 1,..., n k ways of doing A k, then there are n 1 n 2... n k ways of doing A Işıl Dillig, CS243: Discrete Structures Combinatorics 7/35 Işıl Dillig, CS243: Discrete Structures Combinatorics 8/35 Example 3 Example 4 A bitstring is a string where each character is either 0 or 1 How many different bit strings of length 7 are there? Decomposition: First assign bit to first character, then to second,..., then to seventh How many ways to assign bit to each character? How many different bitstrings? By extended product rule: 2 2... 2 (7 times) Each license plate consists of 3 letters followed by 3 digits [0-9] How many different license plates are there? Decomposition: How many ways to assign each letter? How many ways to assign each digit? How many different labels for each license plate? This is 2 7 = 128 Işıl Dillig, CS243: Discrete Structures Combinatorics 9/35 Işıl Dillig, CS243: Discrete Structures Combinatorics 10/35 Counting One-to-One Functions How many one-to-one functions are there from a set with 3 elements to a set with 5 elements? Recall: In a one-to-one function, different elements in domain cannot be assigned to same element in codomain Decomposition: Assign first element in domain, then second element, then third element How many ways to assign first element? How many ways to assign second element? How many ways to assign third element? Sum Rule Two basic very useful decomposition rules: 1. Product rule 2. Sum rule Suppose a task A can be done either in way B or in way C Suppose there are n 1 ways to do B, and n 2 ways to do C Sum rule: There are n 1 + n 2 ways to do A. How many different functions? Işıl Dillig, CS243: Discrete Structures Combinatorics 11/35 Işıl Dillig, CS243: Discrete Structures Combinatorics 12/35 2

Example 1 Suppose either a CS faculty or CS student must be chosen as representative for a committee There are 14 faculty, and 50 majors How many ways are there to choose the representative? Example 2 A student can choose a senior project from one of three lists First list contains 23 projects; second list has 15 projects, and third has 19 projects Also, no project appears on more than one list How many different projects can student choose? Note: Just like the product rule, the sum rule can be extended to more than two tasks Extended sum rule: If task can be done in one of n 1 or n 2, or..., n k ways, then there are n 1 + n 2 +... + n k ways of doing it What if some of the projects appeared on both lists? Caveat: For sum rule to apply, the possibilities must be mutually exclusive Işıl Dillig, CS243: Discrete Structures Combinatorics 13/35 Işıl Dillig, CS243: Discrete Structures Combinatorics 14/35 More Complex Counting Problems Problems so far required either only product or only sum rule But more complex problems require a combination of both! Example: In a programming language, a variable name is a string of one or two characters. A character is either a letter [a-z] or a digit [0,9]. First character in the string must be a letter. How many possible variable names are there? First, decompose using sum rule. Variable name is either one character or two characters Compute number n 1 of one character names Compute number n 2 of two character names By sum rule, there is n 1 + n 2 names First compute n 1 : How many 1 character names are there? Işıl Dillig, CS243: Discrete Structures Combinatorics 15/35 Işıl Dillig, CS243: Discrete Structures Combinatorics 16/35 Another Example Now, compute n 2 : How many 2 character names are there? For this, decompose using product rule: assign first character first, then second character How many ways to assign first character? How many ways to assign second character? How many 2 character names? By sum rule, total number of variable names = n 1 + n 2 = 26 + 936 = 962 A password must be six to seven characters long A character is upper case letter or digit Each password must contain at least one digit How many possible passwords? First decompose using sum rule: either six or seven characters Thus, number of possible passwords is n 6 + n 7 where n i is number of passwords with i characters Işıl Dillig, CS243: Discrete Structures Combinatorics 17/35 Işıl Dillig, CS243: Discrete Structures Combinatorics 18/35 3

Computing n 6 : How many six-character passwords are there containing at least one digit? For this, compute the total number of six-character passwords; then subtract number of passwords without any digits Total # of 6-char passwords: # of 6-char passwords without any digits: Thus, n 6 = 36 6 26 6 Computing n 7 : How many seven-character passwords are there containing at least one digit? n 7 = Total - # without any digits Total # of 7-char passwords = Those without any digits: n 7 = 36 7 26 7 Total number of passwords = n 6 + n 7 = 72, 200, 220, 480 Işıl Dillig, CS243: Discrete Structures Combinatorics 19/35 Işıl Dillig, CS243: Discrete Structures Combinatorics 20/35 Example 3 How many bitstrings are there of length 6 that do not have two consecutive 1 s? Let F (n) denote the number of bitstrings of length n that do not have two consecutive 1 s We ll first derive a recursive equation to characterize F (n) By the sum rule, F (n) is the sum of: 1. # of n-bit strings starting with 1 not containing 11 2. # of n-bit strings starting with 0 not containing 11 Example 3, cont. How many n-bit strings are there starting with 1 and not containing 11? Since we don t want two consecutive 1 s, second bit must be 0 But the rest can be anything as long as it doesn t contain two consecutive 1 s Thus, the rest = number of bitstrings of length n 2 not containing two consecutive 1 s But this is precisely F (n 2)! Thus, by product rule, there are 1 1 F (n 2) = F (n 2) n-bit strings starting with 1 and not containing 11 Işıl Dillig, CS243: Discrete Structures Combinatorics 21/35 Işıl Dillig, CS243: Discrete Structures Combinatorics 22/35 Example 3, cont. Example 3, cont. How many n-bit strings are there starting with 0 and not containing 11? First bit must be 0 but rest can be anything as long as it doesn t contain 11 How many ways of forming the rest? # of bitstrings of length n 1 not containing 11: By product rule, number of n-bit strings starting with 0, not containing 11 is 1 F (n 1) = F (n 1) Recall: F (n) is sum of: 1. # of n-bit strings starting with 1 not containing 11 2. # of n-bit strings starting with 0 not containing 11 We determined that (1) is F (n 2) We determined that (2) is F (n 1) Therefore, F (n) = F (n 1) + F (n 2) This is a recursive definition, but what are the base cases? Işıl Dillig, CS243: Discrete Structures Combinatorics 23/35 Işıl Dillig, CS243: Discrete Structures Combinatorics 24/35 4

Example 3, cont. What is F (1)? What is F (2)? Original question asks for F (6) Using base cases and recursive definition: What is F (3)? What is F (4)? What is F (5)? What is F (6)? Recall: Sum Rule Recall: Sum rule only applies if a task is as disjunction of two mutually exclusive tasks What do we do if the tasks aren t mutually exclusive? Example: You can choose from set A or set B, but they have some elements in common In such cases, the sum rule is not applicable because common elements counted twice Fortunately, there is a generalization of the sum rule called the inclusion-exclusion principle Işıl Dillig, CS243: Discrete Structures Combinatorics 25/35 Işıl Dillig, CS243: Discrete Structures Combinatorics 26/35 The Inclusion-Exclusion Principle Suppose a set A can be written as union of sets B and C Inclusion-Exclusion Principle: A = B + C B C Inclusion-Exclusion Principle Example How many bit strings of length 8 either start with 1 or end with two bits 00? Let B be the set of bitstrings that start with 1 Let C be the set of bitstrings that end with 00 A C B We want B C By the inclusion-exclusion principle, B C = B + C B C Thus, compute B, C and B C Işıl Dillig, CS243: Discrete Structures Combinatorics 27/35 Işıl Dillig, CS243: Discrete Structures Combinatorics 28/35 First compute B, bitstrings of length 8 that start with 1 What is B? Now compute C, bitstrings of length 8 ending in 00 What is C? Now compute B C, those starting with 1 and ending in 00 What is B C? Number of 8-bit srings that start with 1 and end in 00: 128 + 64 32 = 160 Another Example A company receives 350 applications for job positions 220 of applicants are CS majors, 147 of applicants are business majors, and 51 are double CS and business majors How many are neither CS nor business majors? # of non-cs/non-business applicants = Total applicants - # of CS or business majors What is B CS? The remaining applicants are neither business nor CS: 350 316 = 34 Işıl Dillig, CS243: Discrete Structures Combinatorics 29/35 Işıl Dillig, CS243: Discrete Structures Combinatorics 30/35 5

The Pigeonhole Principle Examples Suppose there is a flock of 36 pigeons and a set of 35 pigeonholes Each pigeon wants to sit in its own hole But since there are less holes than there are pigeons, one pigeon is left without a hole. Consider an event with 367 people. Is it possible no pair of people have the same birthday? Consider function f from a set with k + 1 or more elements to a set with k elements. Is it possible f is one-to-one? Consider n married couples. How many of the 2n people must be selected to guarantee there is at least one married couple? The Pigeonhole Principle: If n + 1 or more objects are placed into n boxes, then at least one box contains 2 or more objects Işıl Dillig, CS243: Discrete Structures Combinatorics 31/35 Işıl Dillig, CS243: Discrete Structures Combinatorics 32/35 Generalized Pigeonhole Principle Examples If n objects are placed into k boxes, then there is at least one box containing at least n/k objects Proof: (by contradiction) Suppose every box contains less than n/k objects Then, there must be less than k ( n/k 1) objects From earlier, we know n k < n k + 1 Adding one and multiply both sides by k: k ( n k 1) < n Thus, this would imply there are less than n objects, a contradiction If there are 30 students in a class, at least how many must be born in the same month? What is the minimum # of students required to ensure at least 6 students receive the same grade (A, B, C, D, F)? Want min n such that n 5 = 6 What is the min # of cards that must be chosen to guarantee three have same suit? (suits:,,, ) Want min n such that n 4 = 3 Işıl Dillig, CS243: Discrete Structures Combinatorics 33/35 Işıl Dillig, CS243: Discrete Structures Combinatorics 34/35 More Examples Suppose there are 25 million phones in a state Each phone number has seven digits, where first digit is [2 9] and other digits are [0 9] What is the minimum number of area codes necessary to guarantee each phone has a unique number? First, compute # of seven-digit phone numbers: Let k be the number of area codes Want to find minimum k such that k = 4 25 10 6 k 8 10 6 Işıl Dillig, CS243: Discrete Structures Combinatorics 35/35 6