Discrete Structures for Computer Science

Slides:



Advertisements
Similar presentations
Counting. Counting = Determining the number of elements of a finite set.
Advertisements

Lecture 4 4.1,4.2 Counting. 4.1 Counting Two Important Principles: Product Rule and Sum Rule. Product Rule: Assume we need to perform procedure 1 AND.
Counting Chapter 6 With Question/Answer Animations.
Recursively Defined Functions
Section 4.1: The Basics of Counting As we have seen, one way to count the number of objects in a finite set S is to produce a one-to-one correspondence.
College of Information Technology & Design
Today Today: Reading: –Read Chapter 1 by next Tuesday –Suggested problems (not to be handed in): 1.1, 1.2, 1.8, 1.10, 1.16, 1.20, 1.24, 1.28.
Copyright © Zeph Grunschlag, Counting Techniques Zeph Grunschlag.
1 Section 4.1 Basics of Counting. 2 Basic Counting Principles: Sum Rule Suppose you have two tasks to perform: –The first task can be done in n 1 ways;
CSE115/ENGR160 Discrete Mathematics 04/10/12
CSE 321 Discrete Structures Winter 2008 Lecture 16 Counting.
Combinations We should use permutation where order matters
Recursive Definitions Rosen, 3.4 Recursive (or inductive) Definitions Sometimes easier to define an object in terms of itself. This process is called.
Copyright © Cengage Learning. All rights reserved. CHAPTER 9 COUNTING AND PROBABILITY.
1 Discrete Structures – CNS2300 Text Discrete Mathematics and Its Applications (5 th edition) Kenneth H. Rosen Chapter 4 Counting.
4. Counting 4.1 The Basic of Counting Basic Counting Principles Example 1 suppose that either a member of the faculty or a student in the department is.
Discrete Mathematics CS 2610 March 26, 2009 Skip: structural induction generalized induction Skip section 4.5.
Counting Chapter 6 With Question/Answer Animations.
Chapter The Basics of Counting 5.2 The Pigeonhole Principle
MAT 2720 Discrete Mathematics Section 6.1 Basic Counting Principles
Basic Counting Lecture 12: Oct 28. This Lecture We will study some basic rules for counting. Sum rule, product rule, generalized product rule Permutations,
Basic Counting. This Lecture We will study some basic rules for counting. Sum rule, product rule, generalized product rule Permutations, combinations.
Chapter The Basics of Counting 5.2 The Pigeonhole Principle
Fall 2002CMSC Discrete Structures1 One, two, three, we’re… Counting.
Constraint Satisfaction Problems (CSPs) CPSC 322 – CSP 1 Poole & Mackworth textbook: Sections § Lecturer: Alan Mackworth September 28, 2012.
Dr. Eng. Farag Elnagahy Office Phone: King ABDUL AZIZ University Faculty Of Computing and Information Technology CPCS 222.
1 Lecture 4 (part 1) Combinatorics Reading: Epp Chp 6.
ICS 253: Discrete Structures I Counting and Applications King Fahd University of Petroleum & Minerals Information & Computer Science Department.
The Basics of Counting Section 6.1.
Section Section Summary The Product Rule The Sum Rule The Subtraction Rule The Division Rule Examples, Examples, and Examples Tree Diagrams.
CSNB143 – Discrete Structure
Counting Techniques. L172 Agenda Section 4.1: Counting Basics Sum Rule Product Rule Inclusion-Exclusion.
Discrete Structures Counting (Ch. 6)
Discrete Mathematics, 1st Edition Kevin Ferland Chapter 6 Basic Counting 1.
Counting Principles Multiplication rule Permutations Combinations.
2/24/20161 One, two, three, we’re… Counting. 2/24/20162 Basic Counting Principles Counting problems are of the following kind: “How many different 8-letter.
Introduction Suppose that a password on a computer system consists of 6, 7, or 8 characters. Each of these characters must be a digit or a letter of the.
Section Basic Counting Principles: The Product Rule The Product Rule: A procedure can be broken down into a sequence of two tasks. There are n 1.
CS 104: Discrete Mathematics
Discrete Mathematics and Its Applications Sixth Edition By Kenneth Rosen Chapter 5 Counting 歐亞書局.
Section The Product Rule  Example: How many different license plates can be made if each plate contains a sequence of three uppercase English letters.
COUNTING Discrete Math Team KS MATEMATIKA DISKRIT (DISCRETE MATHEMATICS ) 1.
CSC 321: Data Structures Fall 2015 Counting and problem solving
ICS 253: Discrete Structures I
Chapter 5, Section 5.1 The Basics of Counting
Copyright © Zeph Grunschlag,
The Pigeonhole Principle
Discrete Structures for Computer Science
COCS DISCRETE STRUCTURES
Copyright © Zeph Grunschlag,
Counting Chapter 6 With Question/Answer Animations
Recursively Defined Functions
CS100: Discrete structures
8.3 Counting Apply the fundamental counting principle
Math/CSE 1019: Discrete Mathematics for Computer Science Fall 2011
Basic Counting.
Counting, Permutations, & Combinations
CSE 321 Discrete Structures
Counting techniques Basic Counting Principles, Pigeonhole Principle, Permutations and Combinations.
Counting Discrete Mathematics.
Basic Counting Lecture 9: Nov 5, 6.
Discrete Structures Counting.
Representations of Integers
Discrete Mathematics and its Applications
Copyright © Zeph Grunschlag,
Copyright © Zeph Grunschlag,
Independence and Counting
Independence and Counting
Independence and Counting
9.1 Basic Combinatorics.
Presentation transcript:

Discrete Structures for Computer Science Presented By: Andrew F. Conn Lecture #15: Counting Basics Monday, October 31st, 2016

Today’s Topics Introduction to combinatorics Product rule Sum rule

Just think of this as a fancy word for “counting” What is combinatorics? Combinatorics is the study of arrangements of discrete objects. Many applications throughout computer science: Algorithm complexity analysis Resource allocation & scheduling Security analysis … Today, we will learn the basics of counting. More advanced topics will be covered in later lectures. Just think of this as a fancy word for “counting”

How many valid passwords are there? A motivating example… To access most computer systems, you need to login with a user name and a password. Suppose that for a certain system Passwords must contain either 6, 7, or 8 characters Each character must be an uppercase letter or a digit Every password must contain at least one digit Tell them that we will answer this question by the end of lecture, but need to learn some basics first How many valid passwords are there?

Solving these types of problems requires that we learn how to count complex objects Fortunately, we can solve many types of combinatorial problems using two simple rules: The product rule The sum rule Product rule: good for counting problems that can be broken into several independent choices Sum rule: Good for problems that have multiple options or “cases” to consider Sequential steps VS choices

Product rule applies when a counting problem can be broken into multiple tasks The Product Rule: Suppose a procedure can be broken into a sequence 𝑡 1 , 𝑡 2 ,…, 𝑡 𝑘 of tasks. Further, let there be 𝑛 1 , 𝑛 2 ,…, 𝑛 𝑘 ways to complete each task. Then there are 𝑛 1 × 𝑛 2 ×…× 𝑛 𝑘 ways to complete the procedure. To apply the product rule, do the following: Identify each task 𝑡 1 ,…, 𝑡 𝑘 For each task 𝑡 𝑖 , determine the 𝑛 𝑖 , the number of possible ways to complete 𝑡 𝑖 Compute 𝑛 1 × 𝑛 2 ×…× 𝑛 𝑘 Let’s look at a few examples…

An easy example: Assigning offices Example: It is Alice’s and Bob’s first day of work at Acme, Inc. If there are 10 unused offices at Acme, how many ways can Alice and Bob be assigned an office? Step 1: Determine tasks Give Alice an office Give Bob an office Step 2: Count possible completions Can give any one of 10 offices to Alice Can give any one of the remaining 9 offices to Bob Step 3: Compute the product Alice and Bob can be assigned offices in 10×9=90 ways! Steps correspond to “algorithm” on last slide

Auditorium Seating Example: The chairs in an auditorium are to be labeled using an upper case letter and a positive number not exceeding 100 (e.g., B23). What is the maximum number of seats that can be placed in the auditorium? Solution: Task 1: Count the letters that can be used (26) Task 2: Count the numbers that can be used (100) So, the auditorium can hold 26×100=2600 chairs.

Counting Bit Strings Example: How many bit strings of length 5 are there? Solution: Task 1: Choose first bit (2) Task 2: Choose second bit (2) Task 3: Choose third bit (2) Task 4: Choose fourth bit (2) Task 5: Choose fifth bit (2) So, there are 2×2×2×2×2= 2 5 =32 bit strings of length 5 Talked about # of binary strings a lot. Here’s a combinatoric explanation.

Counting 1-to-1 Functions Example: How many 1-to-1 functions are there mapping a set A containing 𝑚 elements to another set B containing 𝑛 elements (assuming that 𝑚≤𝑛)? Solution: Task 1: Map first element of A to B (𝑛) Task 2: Map second element of A to B (𝑛−1) Task 3: Map third element of A to B (𝑛−2) … Task m: Map last element of A to B (𝑛−𝑚+1) So, there are a total of 𝑛×(𝑛−1)×…×(𝑛−𝑚+1) 1-to-1 functions from A to B Note that each choice eliminates an element of the codomain, since the function must be 1-to-1

License Plates Example: Suppose that in some state, license plates consist of three letters followed by three decimal digits. How many valid license plates are there? Solution: There are 26 3 × 10 3 =17,576,000 possible valid license plates A B C 1 2 3 26 choices for each 10 choices for each Unlike last problem where each choice eliminated future choices, here all of our choices are INDEPENDENT. So the plate AAA222 is valid.

Group Work! Problem 1: How many subsets does a finite set 𝑆 have, assuming that 𝑆 =𝑛? (Hint: think about a bitmap representation of the set.) Problem 2: In North America, phone numbers are of the form NXX-NXX-XXXX, where 2≤𝑁≤9 and 0≤𝑋≤9. How many valid telephone numbers are there?

The sum rule applies when a single task can be completed using several different approaches The Sum Rule: Suppose that a single task can be completed in either one of 𝑛 1 ∨ 𝑛 2 ∨…∨ 𝑛 𝑘 ways. Then the task can be completed in 𝑛 1 + 𝑛 2 +…+𝑛_𝑘 ways. Note: We can break the set of all possible solutions to the problem into disjoint subsets. E.g., if we have 𝑘 “classes” of solutions, then 𝑆= 𝑆 1 ∪ 𝑆 2 ∪…∪ 𝑆 𝑘 ∀𝑖,𝑗 𝑆 𝑖 ⊈ 𝑆 𝑗 𝑆 = 𝑆 1 ∪ 𝑆 2 ∪…∪ 𝑆 𝑘 = 𝑆 1 + 𝑆 2 +…+ 𝑆 𝑘 Since 𝑆 1 ,…, 𝑆 𝑘 are disjoint = 𝑛 1 + 𝑛 2 +…+ 𝑛 𝑘 Tell them that this is a ridiculously “common sense” rule… S1 is first type of solution, S2 is second type of solution, etc

University Committees Example: Suppose that either a CS professor or a CS graduate student can be nominated to serve on a particular university committee. If there are 21 CS professors and 101 CS graduate students, how many ways can this seat on the committee be chosen? Solution: Let P be the set of professors G be the set of graduate students S be the solution set, with S = P ∪ G Then there are 𝑆 = 𝑃∪𝐺 = 𝑃 + 𝐺 =21+101=122 ways to fill the empty seat on the committee.

The product and sum rules are kind of boring… Most interesting counting problems cannot be solved using the product rule or the sum rule alone… … but many interesting problems can be solved by combining these two approaches! Let’s revisit our password example…

Use the product rule to count passwords of each possible length! Passwords revisited… To access most computer systems, you need to login with a user name and a password. Suppose that for a certain system Passwords must contain either 6, 7, or 8 characters Each character must be an uppercase letter or a digit Every password must contain at least one digit Use the product rule to count passwords of each possible length! Choices: Sum rule! Heuristic: (1) “either/or” -> sum rule, (2) indep. Choice -> prod. rule How many valid passwords are there?

First, we’ll apply the sum rule Let: P6 = Set of passwords of length 6 P7 = Set of passwords of length 7 P8 = Set of passwords of length 8 S = P6 ∪ P7 ∪ P8 Note: 𝑆 = 𝑃 6 + 𝑃 7 + 𝑃 8 Since each element of 𝑃 6 , 𝑃 7 , and 𝑃 8 is made up of independent choices of letters and numbers, we can apply the product rule to determine 𝑃 6 , 𝑃 7 , and | 𝑃 8 | Stress disjointedness of P6-8 means we can use sum rule. Next lecture we’ll cover what to do if sets aren’t disjoint

Recall: a password must contain at least one number! Observation: To figure out the number of 6-character passwords containing at least one number, it is easier for us to count all 6-character passwords and then subtract away those passwords not containing a number. Note: there are 26+10 6 = 36 6 6-character passwords 26 6 6-character passwords not containing a digit So, 𝑃 6 = 36 6 – 26 6 =1,867,866,560 Ask if they can figure out how to count passwords without a number before pulling up the “observation”’ Explain first bullet point: 26 for letters, 10 for numbers

Wrapping it all up… We can compute 𝑃 6 = 36 6 – 26 6 =1,867,866,560 𝑃 7 = 36 7 – 26 7 =70,332,353,920 𝑃 8 = 36 8 – 26 8 =208,827,064,576 By leveraging our earlier observation that 𝑆 = 𝑃 6 + 𝑃 7 + 𝑃 8 , we can conclude that there are 2,612,282,842,880 valid passwords for our target system. Interesting note: Although this is a HUGE number of possible passwords, in practice, the space of passwords used is much smaller. People tend to use words from the dictionary or, worse yet, words that have special meaning to them (and are thus easier to guess).

Group Work! Problem 3: A committee is formed by choosing one representative from each of the 50 US states. This representative is either the governor of that state, or one of the two senators from that state. How many possible ways are there to form this committee? Problem 4: How many license plates can be made using either two letters followed by four digits or two digits followed by four letters?

Final Thoughts Combinatorics is just a fancy word for counting! There are many any uses of combinatorics throughout computer science We can solve a variety of interesting problems using simple rules like the product rule and the sum rule Next time: Inclusion/Exclusion principle (Section 6.1) The pigeonhole principle (Section 6.2)