Combinatorics University of Akron Programming Team 9/23/2011.

Slides:



Advertisements
Similar presentations
Permutations and Combinations Rosen 4.3. Permutations A permutation of a set of distinct objects is an ordered arrangement these objects. An ordered arrangement.
Advertisements

Counting Chapter 6 With Question/Answer Animations.
Great Theoretical Ideas in Computer Science.
CSCE 2100: Computing Foundations 1 Combinatorics Tamara Schneider Summer 2013.
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
Counting II: Recurring Problems And Correspondences Great Theoretical Ideas In Computer Science Steven RudichCS Spring 2004 Lecture 10Feb 12, 2004Carnegie.
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.
Lecture 5 Counting 4.3, Permutations r-permutation: An ordered arrangement of r elements of a set of n distinct elements. Example: S={1,2,3}:
CSE 321 Discrete Structures Winter 2008 Lecture 16 Counting.
Counting II: Pascal, Binomials, and Other Tricks Great Theoretical Ideas In Computer Science A. Gupta D. Sleator CS Fall 2010 Lecture 8Sept. 16,
Recursive Definitions Rosen, 3.4 Recursive (or inductive) Definitions Sometimes easier to define an object in terms of itself. This process is called.
The Basics of Counting: Selected Exercises. Copyright © Peter Cappello2 Sum Rule Example There are 3 sizes of pink shirts & 7 sizes of blue shirts. How.
Consecutive Numbers Algebra I.
Exam 1 Review 5.1, , 8.1, 8.2.
Chapter The Basics of Counting 5.2 The Pigeonhole Principle
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.
Counting Principles. What you will learn: Solve simple counting problems Use the Fundamental Counting Principle to solve counting problems Use permutations.
Binomial Coefficients, Inclusion-exclusion principle
Chapter 6 With Question/Answer Animations 1. Chapter Summary The Basics of Counting The Pigeonhole Principle Permutations and Combinations Binomial Coefficients.
Notes 9.2 – The Binomial Theorem. I. Alternate Notation A.) Permutations – None B.) Combinations -
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.
THE NATURE OF COUNTING Copyright © Cengage Learning. All rights reserved. 12.
MA/CSSE 473 Day 14 Permutations wrap-up Subset generation (Horner’s method)
Lecture 5 Counting 4.3, Permutations r-permutation: An ordered arrangement of r elements of a set of n distinct elements. Example: S={1,2,3}:
1 Binomial Coefficients CS 202 Epp, section ??? Aaron Bloomfield.
Simple Arrangements & Selections. Combinations & Permutations A permutation of n distinct objects is an arrangement, or ordering, of the n objects. An.
1 Set Theory Chapter 3. 2 Chapter 3 Set Theory 3.1 Sets and Subsets A well-defined collection of objects (the set of outstanding people, outstanding is.
Counting CSC-2259 Discrete Structures Konstantin Busch - LSU1.
Huffman Encodings Section 9.4. Data Compression: Array Representation Σ denotes an alphabet used for all strings Each element in Σ is called a character.
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,
Pascal’s Triangle and the Binomial Theorem (x + y) 0 = 1 (x + y) 1 = 1x + 1y (x + y) 2 = 1x 2 + 2xy + 1y 2 (x + y) 3 = 1x 3 + 3x 2 y + 3xy 2 +1 y 3 (x.
Combinatorics CSLU Fall 2007 Cameron McInally Fordham University.
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.
Copyright © Peter Cappello 2011 Simple Arrangements & Selections.
State space search Represented by a four-tuple [N,A,S,GD], where: N is the problem space A is the set of arcs (or links) between nodes. These correspond.
Vector program patterns Vectors contain many elements, so loops are common. Counted processing // Print the first 3 elements. for (int i = 0; i < 3; i++)
CS 104: Discrete Mathematics
L14: Permutations, Combinations and Some Review EECS 203: Discrete Mathematics.
Polynomials Count! CS Lecture 9 X1 X1 X2 X2 + + X3 X3.
Recursively Defined Sequences Lecture 40 Section 8.1 Wed, Apr 11, 2007.
Permutations & Combinations: Selected Exercises. Copyright © Peter Cappello2 Preliminaries Denote the # of arrangements of some k elements of a set of.
Generating Permutations and Combinations “Traveling Salesman Problem” – A salesman must visit 6 cities; what’s the best order in which to visit them? Assume.
Section 6.3. Section Summary Permutations Combinations.
Combinatorics. What is Combinatorics? Wide ranging field involving the study of discrete objects.
Chapter 11 Sorting Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich, Tamassia and Mount.
L14: Permutations, Combinations and Some Review
COCS DISCRETE STRUCTURES
Section 8.3 PROBABILITY.
Generalized Permutations & Combinations: Selected Exercises
Consecutive Numbers Algebra I.
Warm Up Identify the slope and y-intercept of each equation. Then graph. 1. Y = -5X X + 5Y = X = Y = 12.
Permutations and Combinations
The Binomial Theorem.
Combinatorics.
Permutations and Combinations
Combinatorics.
Combinatorics: Combinations
Permutations and Combinations
Basic Counting.
Combinatorics.
CSE 321 Discrete Structures
Basic Counting Lecture 9: Nov 5, 6.
Permutations and Combinations
Combinatorics.
Section 11.7 The Binomial Theorem
Presentation transcript:

Combinatorics University of Akron Programming Team 9/23/2011

Permutations Ways of ordering a set of items. - OR -

Counting Permutations Depends on the size of the set S of items. ◦ |S| = 1  1 Permutation ◦ |S| = 2  2 Permutations ◦ |S| = 3  ?

Counting Permutations |S| = 3  6 Permutations

Counting Permutations |S| = 3 ◦ Any of the three items can go in the 1 st spot.  Any of the remaining two items can go in the 2 nd spot  Any of the remaining one items can go into the 3 rd spot. ◦ 3 options * 2 options * 1 option  6 total options

Counting Permutations In general, there are |S|! (factorial) permutations. Knowing how quickly factorials grow lets us know whether enumerating all the permutations of a set is reasonable within the confines of a programming competition. Countms / perm in 15s 6! = ! = 5, ! = 40, ! = 362, ! = 3,628, ! = 39,916,

Generating Permutations Bottom Up If you knew all the permutations of the set {A, B, C}, could you utilize that to quickly generate the permutations of {A, B, C, D}? ◦ Permutations of {A, B, C}  (A, B, C)  (A, C, B)  (B, A, C)  (B, C, A)  (C, A, B)  (C, B, A)

Generating Permutations Bottom Up Easier example: If we know all the permutations of {A}, can we generate all the permutations of {A, B}? ◦ Permutations of {A}  (A) ◦ Let’s add B to the existing permutation. Two options:  Add B to the right of A  (A, B)  Add B to the left of A  (B, A)

Generating Permutations Bottom Up Permutations of {A, B} ◦ (A, B) ◦ (B, A) Let’s generate the permutations of {A, B, C} ◦ Using (A, B) as a starting point  Add C to the right: (A, B, C)  Add C in the middle: (A, C, B)  Add C on the left: (C, A, B) ◦ Using (B, A) as a starting point  Add C to the right: (B, A, C)  Add C to the middle: (B, C, A)  Add C to the left: (C, B, A)

Generating Permutations Bottom Up BottomUpPermutations(List list) ◦ List results ◦ Add 1 st element of list (as a new list) to results ◦ for(i = 2 to |list|) {  List nextLengthResults  for(List permutation in results) {  Add the i th elemnt of list to each position in permutation }  results = nextLengthResults } ◦ return results

Generating Permutations Bottom Up – CODE! public static List > BottomUp(List items) { List > results = new ArrayList >(); List initial = new ArrayList (); initial.add(items.get(0)); results.add(initial); for(int i = 1; i < items.size(); i++) { List > nextLengthResults = new ArrayList >(); for(List permutation: results) { for(int j = 0; j <= permutation.size(); j++) { // Add the i th item to the j th position & add that to the nextLengthResults ArrayList tempPerm = new ArrayList (permutation); tempPerm.add(j, items.get(i)); nextLengthResults.add(tempPerm); } results = nextLengthResults; } return results; }

Generating Permutations Special Orderings Minimum Change ◦ Each consecutive permutation differs by only one swap of two items.  (1 2 3) (1 3 2) (3 1 2) (3 2 1) (2 3 1) (2 1 3) Lexicographic order ◦ Consider the input list to be in “alphabetic order.” Then the lexicographic order gives all permutations in combined alphabetic order ◦ Input list: (A B C)  (A B C)  (A C B)  (B A C)  (B C A)  (C A B)  (C B A)

Subsets Pick as many or few items from this set as you’d like:

Subsets

Counting Subsets Depends on the size of the set S of items. ◦ |S| = 0  1 Subset ◦ |S| = 1  2 Subsets ◦ |S| = 2  4 Permutations ◦ |S| = 3  ?

Counting Subsets |S| = 3  8 Subsets

Counting Subsets |S| = 3 ◦ Item 1 can either be part of the subset or not.  2 options ◦ Item 2 can either be part of the subset or not.  2 options * 2 options = 4 options ◦ Item 3 can either be part of the subset or not.  4 options * 2 options = 8 options

Counting Subsets In general, there are 2 |S| subsets (exponential). Knowing how quickly exponentials grow lets us know whether enumerating all the subsets of a set is reasonable within the confines of a programming competition. Countms / perm in 15 s 2 6 = = 1, = = = =

Generating Subsets Bottom Up BottomUpSubsets(List list) ◦ If list has 0 elements  return {Ø} ◦ results := new List ◦ head := first element of the list ◦ headlessList := list with head removed ◦ for( List subset in BottomUpSubsets(headlessList)) {  Add subset to results  Add subset + head to results } ◦ return results

Generating Subsets Bottom Up – CODE! public static List > bottomUp(Set originalSet) { List > result = new ArrayList >(); if(originalSet.size() == 0) { result.add(new HashSet ()); return result; } List list = new ArrayList (originalSet); T first = list.get(0`); Set remainder = new HashSet (list.subList(1, list.size())); for (Set without : bottomUp(remainder)) { Set with = new HashSet (without); with.add(first); result.add(without); result.add(with); } return result; }

Generating Subsets Another Approach Can take advantage of bit representations of integers. Consider S = (A, B, C), using ints in [0, 2 |S| -1] ◦ 0000_ _ _ ◦ 1001_ _ C ◦ 2010_ B _ ◦ 3011_ B C ◦ 4100A _ _ ◦ 5101A _ C ◦ 6110A B _ ◦ 7111A B C

Counting Topics Binomial coefficients ◦ n choose k  “k member committee from n people”  Alternate notation nCk  There are n! / (n-k)!k!) ways.  nCk = (n-1)C(k-1) + (n-1)C(k)  Ex: “Num paths from (0, 0) to (10, 10) in plane only making steps in the positive directions.” ◦ Pascals Triangle relationship ◦ Coefficients on (a+b) n

Counting Topics Stirling numbers ◦ First kind – permutations on n with exactly k cycles. ◦ Second kind – ways to partition a set of n objects into k groups. Catalan numbers ◦ Number of ways to balance n sets of parentheses  Cn = 1/(n+1) * (2nCn) Eulerian Numbers ◦ Number of permutations of length n with k ascending sequences. Solving recurrence relations for closed form solutions.

Other Combinatorics Problems Permutations with duplicate elements ◦ (A, A, B)  (A, A, B) (A, B, A) (B, A, A) “Strings” of length n on string s ◦ Length 2 over “ab”  “aa”, “ab”, “ba”, “bb”

Images / 19/ / 3/