Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Chapter 4.2 Counting Read: 4.2 Next Class: 4.3 Motivation 1 Section 3.2 We have already seen that different sets can have different numbers of elements. Even infinite sets can have different complexities. Counting of the number of elements in a set (or combinatorics) is important in statistics where it is used to compute the probability of the occurrence of a given event. Combinatorics is an important technique for complexity analysis of algorithms. Counting 1 Counting 2 The idea is to find out how many members are present in a finite set. Principles of counting answer the following kind of questions: How many four digit numbers can there be if repetition of numbers are allowed and if repetition of numbers are not allowed? If a man has 4 suits, 8 shirts and 5 ties, how many outfits can he put together? Counting problems are often cast as a decision problem where it is analyzed how many possible outcomes exist for a specific sequence of choices or events. Section 3.2 Counting Multiplication Principle 3 Section 3.2 Multiplication Principle: If there are n possible outcomes for a first event and m possible outcomes for a second event, then there are nm possible outcomes for the sequence of two events. Hence, from the multiplication principle, it follows that for two sets A and B |AB| = |A|.|B| Example: A child is allowed to choose one jellybean out of two jellybeans, one red and one black, and one gummy bear out of three gummy bears, yellow, green, and white. How many different sets of candy can the child have? Counting 2 Example: Multiplication Principle 4 Section 3.2 There are 23=6 or 32=6 possible outcomes as seen from the following figures Counting Addition Principle 5 Section 3.2 Addition Principle: If A and B are disjoint events with n and m outcomes, respectively, then the total number of possible outcomes for event “A or B” is n+m. If A and B are disjoint sets, then |A B| = |A| + |B| using the addition principle. Example: If you can decide between 5 different cars and 4 trucks, the total number of choices is 9. Counting 3 Addition Principle (cont’d) 6 Prove that if A and B are finite sets then |A-B| = |A| - |A B| and |A-B| = |A| - |B| if B A (A-B) (A B) = (A B) (A B) = A (B B) =AU =A Also, A-B and A B are disjoint sets, therefore using the addition principle |A| = | (A-B) (A B) | = |A-B| + |A B| Hence, |A-B| = |A| - |A B| If B A, then A B = B Hence, |A-B| = |A| - |B| Section 3.2 Counting Multiplication and Addition Rules 7 Section 3.2 Note: While the addition principle acts within one decision level, the multiplication principle operates across multiple decision levels. Both principles can be combined to address more complex counting problems. Example 1: How many possible outcomes are there if you 3 times in a row either roll a die or flip a coin each time? Example 2: How many different outcomes are there if 3 numbers are drawn in sequence out of a bucket containing the numbers 0 -9? Example 3: How many possibilities are there for 3 consecutive rolls of a die without two consecutive rolls leading to the same number ? Counting 4 Decision trees 8 Section 3.2 Trees that provide the number of outcomes of an event based on a series of possible choices are called decision trees. Decision trees are often used to visualize and analyze the number of possibilities for a selection task. In a decision tree the nodes correspond to decision points. The branches leaving such nodes represent different choices or events. The different levels of the tree thus correspond to sequential decisions and the leaves represent the possible outcomes (or elements of the set). Counting Decision trees (cont’d) 9 Section 3.2 Example: Tony is pitching pennies. Each toss results in heads (H) or tails (T). How many ways can he toss the coin five times without having two heads in a row? There are 13 possible outcomes as seen from the tree. Counting 5 Exercises 10 Exercise: A dinner allows you to select from five appetizers, three salads, four entrees, and three beverages. 1) How many different dinners are there? Section 3.2 2) How many different dinners are there if you may have an appetizer or a salad but not both? Counting Exercises 11 Exercise: Use the addition and multiplication principles to determine the number of possible outcomes for the following problems. a) John performs an experiment where he either rolls a die or flips two coins simultaneously. If he repeats this experiment 4 times in a row, how many possible outcomes can he obtain? Section 3.2 b) If we flip a coin 5 times in a row, how many possible outcomes are there which contain an odd numbers of heads ? c) How many different 15-digit binary numbers can be formed ? Counting 6 Exercises 12 Section 3.2 Exercise: Draw a decision tree to find the number of binary strings of length 4 that do not have consecutive 0s. Counting 7