csce 2100: computing foundations 1 combinatorics tamara schneider summer 2013
TRANSCRIPT
- Slide 1
- CSCE 2100: Computing Foundations 1 Combinatorics Tamara Schneider Summer 2013
- Slide 2
- Computer Science Approximations 2 10 = 1024 This is about 1000 (1K) 2 30 = (2 10 ) 3 = (1024) 3 This is about 1000 3 (1G) 4*2 30 = 4 * (1024) 3 This is about 4*1000 3 (4G) Computer scientists cheat to convert powers of 2 into powers of 10. 2
- Slide 3
- Counting Assignments 3
- Slide 4
- Painting Houses [1] We can paint the first house in 3 different ways 4
- Slide 5
- Painting Houses [2] For each choice of the first assignment, we can paint the second house in 3 different colors 5
- Slide 6
- Painting Houses [3] For each choice of the first 2 assignments, we can paint the third house in 3 different colors 6
- Slide 7
- 7 Painting Houses [4] For each choice of the first 3 assignments, we can paint the fourth house in 3 different colors
- Slide 8
- 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
- Slide 9
- 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
- Slide 10
- Counting Permutations [1] 10
- Slide 11
- Counting Permutations [2] So how many permutations are there for 3 objects? 11
- Slide 12
- Counting Permutations [2] 12
- Slide 13
- 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
- Slide 14
- Ordered Selections 14
- Slide 15
- Horse Race 15
- Slide 16
- 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
- Slide 17
- 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
- Slide 18
- 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
- Slide 19
- 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
- Slide 20
- Counting Combinations: n choose m [1] (n,m) = n!/(n-m)! ordered selections Can be grouped (m) = m! different ways
- Slide 21
- Counting Combinations: n choose m [2] Poker example:
- Slide 22
- 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
- Slide 23
- 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
- Slide 24
- 24 c = 1; for(int i=n; i>n-m; i--) c *= i; for(int i=2; 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