CSE 221: Algorithms and Data Structures Lecture #10 Counting: Easy as 1, 2, C(3,1) Steve Wolfman 2009W1 1.

Slides:



Advertisements
Similar presentations
Combinations A combination is a grouping of things ORDER DOES NOT MATTER.
Advertisements

1 Counting Techniques: Possibility Trees, Multiplication Rule, Permutations.
Counting Chapter 6 With Question/Answer Animations.
Recursively Defined Functions
Counting Techniques: Combinations
Counting and Probability The outcome of a random process is sure to occur, but impossible to predict. Examples: fair coin tossing, rolling a pair of dice,
Multiplication Rule. A tree structure is a useful tool for keeping systematic track of all possibilities in situations in which events happen in order.
CSE115/ENGR160 Discrete Mathematics 04/17/12
Permutations r-permutation (AKA “ordered r-selection”) An ordered arrangement of r elements of a set of n distinct elements. permutation of a set of n.
CSE 321 Discrete Structures Winter 2008 Lecture 16 Counting.
Discrete Mathematics Lecture 6 Alexander Bukharovich New York University.
1 More Counting Techniques Possibility trees Multiplication rule Permutations Combinations.
Chapter 5 Section 5 Permutations and Combinations.
Recursive Definitions Rosen, 3.4 Recursive (or inductive) Definitions Sometimes easier to define an object in terms of itself. This process is called.
1 Permutations and Combinations CS/APMA 202 Epp section 6.4 Aaron Bloomfield.
Unit 7: Probability Lesson 2 Tree Diagrams, fundamental counting principle, sample space lists and tables, permutation, combination, factorials.
Elementary Counting Techniques & Combinatorics Martina Litschmannová K210.
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.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Combinatorics.
Elementary Counting Techniques & Combinatorics
Review of 5.1, 5.3 and new Section 5.5: Generalized Permutations and Combinations.
Math 2 Honors - Santowski
Copyright © Cengage Learning. All rights reserved. CHAPTER 9 COUNTING AND PROBABILITY.
Chapter 5 Possibilities and Probability Counting Permutations Combinations Probability.
Counting. Why counting  Determine the complexity of algorithms To sort n numbers, how many instructions are executed ?  Count the number of objects.
1 Melikyan/DM/Fall09 Discrete Mathematics Ch. 6 Counting and Probability Instructor: Hayk Melikyan Today we will review sections 6.4,
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
Lesson 1.9 Probability Objective: Solve probability problems.
Topics to be covered: Produce all combinations and permutations of sets. Calculate the number of combinations and permutations of sets of m items taken.
Generalized Permutations and Combinations
Number of Elements in a Finite Set. Notation : The number of the elements of the set A will be denoted by n(A) Examples (1): Let: Let: A = {a,b,c,d} B.
Data Structures and Algorithms Discrete Math Review.
Chapter 6 With Question/Answer Animations 1. Chapter Summary The Basics of Counting The Pigeonhole Principle Permutations and Combinations Binomial Coefficients.
Permutations and Combinations
Fall 2002CMSC Discrete Structures1 One, two, three, we’re… Counting.
Methods of Counting Outcomes BUSA 2100, Section 4.1.
Elementary Combinatorics Combinatorics  Deals with enumeration (counting) techniques and related algebra.  Basis of counting XSet |X|No. of elements.
Dr. Eng. Farag Elnagahy Office Phone: King ABDUL AZIZ University Faculty Of Computing and Information Technology CPCS 222.
3. Counting Permutations Combinations Pigeonhole principle Elements of Probability Recurrence Relations.
ICS 253: Discrete Structures I Counting and Applications King Fahd University of Petroleum & Minerals Information & Computer Science Department.
1 Lecture 4 (part 2) Combinatorics Reading: Epp Chp 6.
Counting CSC-2259 Discrete Structures Konstantin Busch - LSU1.
Probability. Basic Concepts of Probability What you should learn: How to identify the sample space of a probability experiment and to identify simple.
The Pigeonhole Principle. The pigeonhole principle Suppose a flock of pigeons fly into a set of pigeonholes to roost If there are more pigeons than pigeonholes,
Discrete Mathematics Lecture # 25 Permutation & Combination.
Counting Principles Multiplication rule Permutations Combinations.
Counting.
CPSC 221: Data Structures Lecture #23 Counting Steve Wolfman (stolen from Alan J. Hu who stole some from me which I stole from Kim Voll) 2011W2.
Chapter 7 – Counting Techniques CSNB 143 Discrete Mathematical Structures.
5.5 Generalized Permutations and 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.
Section The Pigeonhole Principle If a flock of 20 pigeons roosts in a set of 19 pigeonholes, one of the pigeonholes must have more than 1 pigeon.
Chapter 6 With Question/Answer Animations Copyright © McGraw-Hill Education. All rights reserved. No reproduction or distribution without the prior written.
ICS 253: Discrete Structures I Counting and Applications King Fahd University of Petroleum & Minerals Information & Computer Science Department.
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.
Permutations. Permutation: The number of ways in which a subset of objects can be selected from a given set of objects, where order is important. Given.
Section 6.3. Section Summary Permutations Combinations.
11.3 Notes Combinations.
CSE 221: Algorithms and Data Structures Lecture #10 Counting: Easy as 1, 2, C(3,1) Steve Wolfman 2010W2.
Elementary Counting Techniques & Combinatorics
CSC-2259 Discrete Structures
COCS DISCRETE STRUCTURES
Counting Principals, Permutations, and Combinations
Counting, Permutations, & Combinations
Permutations.
CS100: Discrete structures
Basic Counting.
Presentation transcript:

CSE 221: Algorithms and Data Structures Lecture #10 Counting: Easy as 1, 2, C(3,1) Steve Wolfman 2009W1 1

Learning Goals After this unit, you should be able to: Apply counting principles to determine the number of arrangements or orderings of discrete objects, with or without repetition, and given various constraints. Use appropriate mathematical constructs to express a counting problem (e.g. counting passwords with various restrictions placed on the characters within). Identify problems that can be expressed and solved as a combination of smaller sub problems. When necessary, use decision trees to model more complex counting problems. 2

Today’s Outline Multiplication Principle Addition Principle Inclusion/Exclusion Principle Combinations and Permutations –r-permutations, no repetition –r-combinations, no repetition –r-permutation, with repetition –r-combinations, with repetition –variants 3

In CS, we often encounter situations where we want to count the number of possible outcomes of an event. For example, we may wish to determine: the number of possible paths to follow in a directed network (graph), the number of possible 5-8 character passwords, etc.

Suppose that the customers of a bank are asked to use 3-digit PINs to protect their accounts when using the bank’s ATM machines. If the other constraints are: no 2 digits can be the same, and the only allowable digits are 1, 2, 3, & 4, how many PINs are possible? (a) Describe the problem in mathematical notation.

(b) Model the problem using a tree diagram.

Multiplication Principle (Product Rule) If an operation consists of t steps and: Step 1 can be performed in n 1 ways, Step 2 can be performed in n 2 ways, … Step t can be performed in n t ways, then the entire operation can be performed in n 1 n 2 …n t different ways. Example: How many postal codes begin with the letter V and end with the digit 4? __ __ __

Example: Use the multiplication principle to prove that the number of subsets of a set containing n elements is 2 n.

Example: Suppose a programming language requires you to define variable names (identifiers) using exactly 3 different upper case characters. How many different identifiers contain either an A or a B, but not both?

Example: Let X be a set with n elements. How many ordered pairs (A, B) satisfy all of these constraints: A ⊆ X, B ⊆ X, and A ∩ B = ∅ ?

Today’s Outline Multiplication Principle Addition Principle Inclusion/Exclusion Principle Combinations and Permutations –r-permutations, no repetition –r-combinations, no repetition –r-permutation, with repetition –r-combinations, with repetition –variants 11

Addition Principle (Sum Rule) If X 1, X 2, …, X t are pairwise disjoint sets (i.e., X i ∩ X j = ∅ ∀ i ∀ j s.t. i, j ∈ {1, 2, …, t }, i ≠ j), then the number of ways to select an element from any of X 1 or X 2 or … or X t is: | X 1 | + | X 2 | + … + | X t |

Example: Suppose a user is asked to create an alphanumeric password consisting of at least 6 characters, but no more than 8 characters. How many different passwords are possible?

Back-of-the-envelope calculation. For the previous example, roughly how long would it take for a program to perform a brute-force attack to discover a user’s password, if we assume (guess?) that a million passwords can be tested each second? Best case? Average case? Worst case? Side thought: Common passwords (when “128-bit” security is no better than 10-bit or 20-bit security).

Example: Suppose a user is asked to create an alphanumeric password consisting of at least 6 characters, but no more than 8 characters, but this time, at least 1 of the chars. has to be a number. (a) From a social engineering perspective, do you expect the password to be more secure, or less secure? (b) How many possible combinations are there this time?

Today’s Outline Multiplication Principle Addition Principle Inclusion/Exclusion Principle Combinations and Permutations –r-permutations, no repetition –r-combinations, no repetition –r-permutation, with repetition –r-combinations, with repetition –variants 16

Inclusion-Exclusion Principle If an object can be found in 2 or more sets at the same time, then we cannot use the addition principle. Why not? If A and B are sets, then the total number of elements in either A or B is given by: | A ∪ B | = | A | + | B | – | A ∩ B | Example using a Venn Diagram:

Example: How many 8-bit strings either start with “1” or end with “00”?

Today’s Outline Multiplication Principle Addition Principle Inclusion/Exclusion Principle Combinations and Permutations –r-permutations, no repetition –r-combinations, no repetition –r-permutation, with repetition –r-combinations, with repetition –variants 19

Permutations & Combinations How many different outcomes are there if you choose r balls from a barrel containing n different balls?

Example: r = 3 Barrel = { A,B,C,D } Order matters ABC ≠ CAB Order doesn’t ABC = CAB Repetition not OK e.g., AAB is not counted ABC, ABD, ACB, ACD, ADB, ADC, BAC, BAD, BCA, BCD, BDA, BDC, CAB, CAD, CBA, CBD, CDA, CDB, DAB, DAC, DBA, DBC, DCA, DCB r-permutations ABC, ABD, ACD, BCD r-combinations Repetition OK e.g., AAB is counted AAA, AAB, AAC, AAD, ABA, ABB, ABC, ABD, … r-permutations w/ rep. AAA, AAB, AAC, AAD, ABB, ABC, ABD, ACC, ACD, ADD, BBB, BBC, BBD, BCC, BCD, BDD, CCC, CCD, CDD, DDD r-combinations w/ rep.

(1) r-Permutations (Order matters, and repetition is not allowed.) An r-permutation of n distinct elements x 1, x 2, …, x n is an ordering of an r-element subset of {x 1, x 2, …, x n }. The number of r-permutations is: P(n, r) = n (r) = Derivation:

Example 1: In how many ways can 5 electoral candidates finish in an election, assuming no ties? Example 2: In how many ways can 7 girls and 3 boys line up, if the boys must stand next to each other?

Example 3: Suppose an operating system has a queue of 3 low priority and 5 high priority processes ready to run. In how many ways could these processes be ordered for execution if 2 low priority processes are not allowed to be executed back to back?

Today’s Outline Multiplication Principle Addition Principle Inclusion/Exclusion Principle Combinations and Permutations –r-permutations, no repetition –r-combinations, no repetition –r-permutation, with repetition –r-combinations, with repetition –variants 25

(2) r-Combinations (Order doesn’t matter, and repetition is not allowed.) An r-combination of n distinct elements x 1, x 2, …, x n is an r- element subset of {x 1, x 2, …, x n }. The number of r-combinations is: C(n, r) = ( ) = Example 4: A donut shop has 10 kinds of donuts. In how many ways can 6 distinct kinds of donuts be selected? Example 5: Show how to derive a relationship between r- permutations and r-combinations.

Today’s Outline Multiplication Principle Addition Principle Inclusion/Exclusion Principle Combinations and Permutations –r-permutations, no repetition –r-combinations, no repetition –r-permutation, with repetition –r-combinations, with repetition –variants 27

(3) r-Permutations with Repetition (Generalized r- Permutations) Here, order matters, and repetition is allowed. Suppose we have a set of n distinct elements x 1, x 2, …, x n and we select a sequence of r elements, allowing repeats. How many different sequences are possible?

Today’s Outline Multiplication Principle Addition Principle Inclusion/Exclusion Principle Combinations and Permutations –r-permutations, no repetition –r-combinations, no repetition –r-permutation, with repetition –r-combinations, with repetition –variants 29

(4) r-Combinations with Repetition (Generalized r- Combinations) Here, order doesn’t matter, and repetition is allowed. Suppose we have a set of n distinct elements x 1, x 2, …, x n. The number of unordered r-element selections from this set, with repetition allowed, is:

Example 8: If a donut shop sells 3 kinds of donuts: plain, glazed, and jelly, then how many possible selections of 7 donuts are there?

Summary of Formulas Order Matters & Repetition is not Allowed Order does not Matter & Repetition is not Allowed Order Matters & Repetition is Allowed Order does not Matter & Repetition is Allowed nrnr n (r) n-1 n ( ) r r+n-1 ( )

Today’s Outline Multiplication Principle Addition Principle Inclusion/Exclusion Principle Combinations and Permutations –r-permutations, no repetition –r-combinations, no repetition –r-permutation, with repetition –r-combinations, with repetition –variants 33

Permutations of Indistinguishable Objects Multinomial Theorem: The number of different permutations of n objects where there are: n 1 indistinguishable type 1 objects n 2 indistinguishable type 2 objects … n k indistinguishable type k objects and n 1 + n 2 + … + n k = n is: Proof:

Example 9: How many strings can be made by reordering the letters PEPPER?

Theorem: The number of ways to place n distinguishable objects into r distinguishable boxes so that n i objects are placed into box i (where i = 1, 2, …, r and n 1 + n 2 + … + n r = n) is: Example 10: How many ways are there to distribute hands of 5 cards to each of 4 players from a deck of 52 cards?

Home Exercise #1: How many non-negative integer solutions are there to the equation: x 1 + x 2 + x 3 + x 4 = 10 ? Home Exercise #2: How would your answer to Home Exercise #1 change if we had these constraints on the number of x i ’s: x 1 ≥ 1, x 2 ≥ 2, x 3 ≥ 0, and x 4 ≥ 0 ? Home Exercise #3: How many times is the following print statement executed, if n = 4? for i 1 = 1 to n for i 2 = 1 to i 1 for i 3 = 1 to i 2 print i 1, i 2, i 3

Learning Goals After this unit, you should be able to: Apply counting principles to determine the number of arrangements or orderings of discrete objects, with or without repetition, and given various constraints. Use appropriate mathematical constructs to express a counting problem (e.g. counting passwords with various restrictions placed on the characters within). Identify problems that can be expressed and solved as a combination of smaller sub problems. When necessary, use decision trees to model more complex counting problems. 38

To Do Finish Project #4 Finish HW #3 Read Epp

Coming Up Final Exam! Yay! 40