CSCE 2100: Computing Foundations 1 Combinatorics Tamara Schneider Summer 2013.

Slides:



Advertisements
Similar presentations
Great Theoretical Ideas in Computer Science for Some.
Advertisements

1 Counting Techniques: Possibility Trees, Multiplication Rule, Permutations.
4/16/2015 MATH 224 – Discrete Mathematics Counting Basic counting techniques are important in many aspects of computer science. For example, consider the.
Counting Chapter 6 With Question/Answer Animations.
Great Theoretical Ideas in Computer Science.
MASTERMIND  Did anyone play the game over the weekend?  Any thoughts on strategy?
Counting Principles The Fundamental Counting Principle: If one event can occur m ways and another can occur n ways, then the number of ways the events.
How many possible outcomes can you make with the accessories?
Multiplication Rule. A tree structure is a useful tool for keeping systematic track of all possibilities in situations in which events happen in order.
Discrete Structures & Algorithms More Counting. + + ( ) + ( ) = ? Counting II: Recurring Problems and Correspondences.
CSE115/ENGR160 Discrete Mathematics 04/17/12
Counting II: Recurring Problems And Correspondences Great Theoretical Ideas In Computer Science Steven RudichCS Spring 2004 Lecture 10Feb 12, 2004Carnegie.
Midterm Review Solutions Math 210G-04, Spring 2011.
Combinatorics CSC 172 SPRING 2002 LECTURE 11 Assignments With Replacement  Example: Passwords  Are there more strings of length 5 built from three.
1 More Counting Techniques Possibility trees Multiplication rule Permutations Combinations.
Permutations and Combinations AII Objectives:  apply fundamental counting principle  compute permutations  compute combinations  distinguish.
CompSci 102 Discrete Math for Computer Science March 22, 2012 Prof. Rodger Lecture adapted from Bruce Maggs/Lecture developed at Carnegie Mellon, primarily.
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.
Combinatorics 3/15 and 3/ Counting A restaurant offers the following menu: Main CourseVegetablesBeverage BeefPotatoesMilk HamGreen BeansCoffee.
CSCE 2100: Computing Foundations 1 Probability Theory Tamara Schneider Summer 2013.
Counting. Techniques for counting Rule 1 Suppose we carry out have a sets A 1, A 2, A 3, … and that any pair are mutually exclusive (i.e. A 1  A 2 =
Basic Counting Lecture 12: Oct 28. This Lecture We will study some basic rules for counting. Sum rule, product rule, generalized product rule Permutations,
3.8 Counting Techniques: Combinations. If you are dealt a hand in poker (5 cards), does it matter in which order the cards are dealt to you? A  K  J.
Basic Counting. This Lecture We will study some basic rules for counting. Sum rule, product rule, generalized product rule Permutations, combinations.
Chapter 6 With Question/Answer Animations 1. Chapter Summary The Basics of Counting The Pigeonhole Principle Permutations and Combinations Binomial Coefficients.
Permutations and Combinations. Objectives:  apply fundamental counting principle  compute permutations  compute combinations  distinguish permutations.
Fall 2002CMSC Discrete Structures1 One, two, three, we’re… Counting.
March 10, 2015Applied Discrete Mathematics Week 6: Counting 1 Permutations and Combinations How many different sets of 3 people can we pick from a group.
COMPSCI 102 Discrete Mathematics for Computer Science.
Discrete Mathematics for Computer Science. + + ( ) + ( ) = ? Counting II: Recurring Problems and Correspondences Chapter 9 slides 1-54.
Great Theoretical Ideas in Computer Science.
Counting CSC-2259 Discrete Structures Konstantin Busch - LSU1.
Spatial Statistics and Spatial Knowledge Discovery First law of geography [Tobler]: Everything is related to everything, but nearby things are more related.
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,
Permutations and Combinations. Objectives:  apply fundamental counting principle  compute permutations  compute combinations  distinguish permutations.
Combinatorics Sep. 23, 2013.
Counting II: Recurring Problems And Correspondences Great Theoretical Ideas In Computer Science John LaffertyCS Fall 2005 Lecture 7Sept 20, 2005Carnegie.
Lesson 0.4 (Counting Techniques)
CS Lecture 8 Developing Your Counting Muscles.
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.
Permutations and Combinations
L14: Permutations, Combinations and Some Review EECS 203: Discrete Mathematics.
Permutations and Combinations AII Objectives:  apply fundamental counting principle  compute permutations  compute combinations  distinguish.
Quiz: Draw the unit circle: Include: (1)All “nice” angles in degrees (2) All “nice” angles in radians (3) The (x, y) pairs for each point on the unit circle.
COUNTING Discrete Math Team KS MATEMATIKA DISKRIT (DISCRETE MATHEMATICS ) 1.
Arrangements and Selections (and how they may be counted)
Permutations and Combinations
Counting Principles Ex. Eight pieces of paper are numbered 1 to 8 and placed in a box. One piece of paper is drawn from the box, its number is written.
L14: Permutations, Combinations and Some Review
Multiplication Rule Combinations Permutations
Introduction to Discrete Mathematics
Developing Your Counting Muscles
COCS DISCRETE STRUCTURES
combinaTorial Analysis
Pascal's Triangle This is the start of Pascal's triangle. It follows a pattern, do you know.
Basic Counting.
Permutations and Combinations
Lesson 11-1 Permutations and Combinations
Combinatorics.
Permutations and Combinations
Basic Counting Lecture 9: Nov 5, 6.
How many possible outcomes can you make with the accessories?
Counting II: Recurring Problems And Correspondences
Counting II: Recurring Problems And Correspondences
Permutations and Combinations
Standard DA-5.2 Objective: Apply permutations and combinations to find the number of possibilities of an outcome.
Permutations and Combinations
Lecture 7: Permutations and Combinations
Presentation transcript:

CSCE 2100: Computing Foundations 1 Combinatorics Tamara Schneider Summer 2013

Computer Science Approximations 2 10 = 1024 This is about 1000 (1K) 2 30 = (2 10 ) 3 = (1024) 3 This is about (1G) 4*2 30 = 4 * (1024) 3 This is about 4* (4G) Computer scientists “ cheat ” to convert powers of 2 into powers of 10. 2

Counting Assignments 3

Painting Houses [1] We can paint the first house in 3 different ways 4

Painting Houses [2] For each choice of the first assignment, we can paint the second house in 3 different colors 5

Painting Houses [3] For each choice of the first 2 assignments, we can paint the third house in 3 different colors 6

7 Painting Houses [4] For each choice of the first 3 assignments, we can paint the fourth house in 3 different colors

Painting Houses [4] So how many ways can we paint these houses? – There are 3 different colors for the first house – For each of the possible assignments there are 3 choices for the second house: 3*3 – For each of the possible assignments there are 3 choices for the third house: 3*3*3 – For each of the possible assignments there are 3 choices for the fourth house: 3*3*3*3 = 3 4 = 81 8

Computer Memory Given 26 bits, how many different bit strings can be produced? Example: names for memory cells 26 different bits 2 possible assignments for each of them (0,1) 2 26 = 67,108,864 bit strings 9

Counting Permutations [1] 10

Counting Permutations [2] So how many permutations are there for 3 objects? 11

Counting Permutations [2] 12

Counting Permutations [3] In general, for n objects there are π(n) = n! permutations. Examples – Lining up 10 horses in a row: π(10) = 10! – 15 people standing in a line: π(15) = 15! 13

Ordered Selections 14

Horse Race 15

Selections without Replacement General formula for π(n,m) – 1 st choice: n – 2 nd choice: n × (n-1) – 3 rd choice: n × (n-1) × (n-2)... – m th choice: n × (n-1) × (n-2) ×... × (n-m+1) π(n,m) = n!/(n-m)! Horse race: π(10,3) = 10!/7! = 10 × 9 × 8 = 720

Unordered Selections [1] ABC ACB BAC BCA CAB CBA All of these cases are different for ordered selections, but count as a single case for unordered selections. 17

Unordered Selections [2] ABC ACB BAC BCA CAB CBA All of these 6 different orders are considered distinct cases for ordered selections, but count as a single case for unordered selections. 18

Poker Hands Each player receives 5 cards from a 52-card deck How many different hands may we receive? What do we need to calculate? – Ordered or unordered selection? 19

Counting Combinations: “ n choose m ” [1] π(n,m) = n!/(n-m)! ordered selections Can be grouped π(m) = m! different ways

Counting Combinations: “ n choose m ” [2] Poker example:

Counting Combinations: “ n choose m ” [3] Basis: There is only one way to pick 0 things. There is only way to pick n things. Inductive Definition

Counting Combinations: “ n choose m ” [4] Induction: Either do not pick the first element and and pick m things from the remaining n-1 elements, or pick the first element and then select m-1 things from the remaining n-1 elements. Inductive Definition

24 c = 1; for(int i=n; i>n-m; i--) c *= i; for(int i=2; i<=m; i++) c /= i;

What is the running time of the algorithm? Do you see any potential problems for the execution of the algorithm? If so, how can we fix this issue? 25 c = 1; for(int i=n; i>n-m; i--) c *= i; for(int i=2; i<=m; i++) c /= i;

Recursive Algorithm for “ n choose m ” Can you find an recurrence relation for the running time of this algorithm? 26 int choose(int n, int m){ if(m n)return 0; //error else if(m==0 || m==n)return 1; //basis else //induction return choose(n-1, m-1) + choose(n-1, m); }

Counting Combinations: Pascal’s Triangle “ n choose m ” and Pascal ’ s Triangle \ 27

Binomial Coefficients 28 (x+y)(x+y)(x+y)(x+y) 16 terms - Why? – x 4 - There is only one possible order. – x 3 y - We have 4 choices for y. The order to select x does not matter. – x 2 y 2 - (4 choose 2) = 6 options for x. The order of y does not matter. – xy 3 - We have 4 choices for x. The order to select y does not matter. – y 4 - There is only one possible order. – (x+y) 4 = x 4 + 4x 3 y + 6x 2 y 2 + 4xy 3 + y 4

Ordering with Identical Items Some items are identical If items are distinguishable, order does matter! Example: abenst (answer: absent ) π(6) = 6! = 720 permutations Example: eilltt π(6) = 6! = 720 permutations “ l ” counted double: 720/2 = 360 permutations “ t ” counted double: 360/2 = 180 permutations 29

Ordering with Identical Items – Formula If there are n items divided into k groups of sizes i 1, i 2,...,i k, items within a group are not distinguishable, but items from different groups are distinguishable, then the number of distinguishable orders of the n items is:

Suppose we have 3 children and 4 apples. In how many ways can we distribute the apples? Distribution of Apples [1] **AAAA*A*AAA*AA*AA*AAA*A*AAAA* A**AAAA*A*AAA*AA*AA*AAA* AA**AAAA*A*AAA*AA* AAA**AAAA*A* AAAA** 31

Distribution of Apples [2] **AAAA*A*AAA*AA*AA*AAA*A*AAAA* A**AAAA*A*AAA*AA*AA*AAA* AA**AAAA*A*AAA*AA* AAA**AAAA*A* AAAA** Unique distribution of 4 As and 2 *s 32

Distribution of Objects to Bins [1] We are given m bins and n identical objects. How many ways can the objects be put into the bins? We have n Os for the objects and (m-1) *s as separators between the bins. This gives us a string of length (n+m-1). Now we can choose n out of the (n+m-1) places to hold the Os. 33

Distribution of Objects to Bins [2] Example: Chuck-a-Luck: 3 dice numbered from 1 to 6. Players bet a dollar on a number. Each player receives as many dollars as his or her number shows. How many different outcomes are there? The dice are indistinguishable. The order does not matter. The numbers 1-6 act as “ bins ”. The dice are objects distributed to them. 34

Distinguishable Objects & Bins [1] Distribute n objects into m bins. There are k different types of objects. Let a i represent the members of class i. Generate a string with – one a i for each member of class i – *’s for boundaries between bins e.g. for k=3, n=5, m = 4 : a 1 a 3 *a 1 **a 2 a 1 So we have n objects with group sizes 3, 2 and 1, and one additional class of *s with m-1 members. 35

Distinguishable Objects & Bins [2] Example: – 3 children – 3 apples, 2 pears, 1 banana – m = 3, n = 6, – k = 3 with i 1 = 3, i 2 = 2, i 3 = 1

Counting Strategies: Sequence of Choices Number of 5-card poker hands that are one-pair. Select rank of the pair (13 different ranks) Select 3 ranks for remaining 3 cards (12 choose 3) Select the suits for the two cards of the pair (4 choose 2) Select suits of remaining cards (4 3 ways) 37

Counting Strategies: Difference of Counts [1] Number of “ straight flushes ” : five cards of consecutive rank of the same suit. Since there are 13 different ranks, one of the first 9 ranks must be the starting point. 1. Select the lowest rank in the straight (9 choices) 2. Select the suit (4 choices) 38

Counting Strategies: Difference of Counts [2] Number of “ straights ” : five cards of consecutive rank that do not have the same suit 1. Select the lowest rank in the straight (9 choices) 2. Select the suit of each of the 5 cards (4 5 choices) 3. Subtract the straight flushes 39

Counting Strategies: Sum of Subcases [1] Toss a sequence of 10 coins. In how many cases will 8 or more be heads? – Exactly 8 heads (10 choose 8) – Exactly 9 heads (10 choose 9) – Exactly 10 heads (10 choose 10)

Counting Strategies: Sum of Subcases [2] Alternate Solution Chuck-a-Luck (3 dies) How many different outcomes are there for this game? – Number of outcomes with 3 different values (6 choose 3) – Number of outcomes with 2 of one value and one other value (6 choices for number that appears twice and 5 choices for number that appears once) – Same number for all dice: 6 different ways

Summary [1] Permutations of n elements: π(n) = n! Ordered selection (m out of n elements): π(n,m) = n!/(n-m)! Unordered selection ( “ n choose m ” ):

Summary [2] Ordering with identical items Distribution of objects to bins Distribution of distinguishable objects to bins