1 / 11

Generating Permutations and Combinations

Learn how to generate permutations and combinations for different scenarios, such as the Traveling Salesman Problem and selecting employees for projects. Explore lexicographic ordering and algorithms for generating permutations and combinations. Homework exercises included.

cpena
Download Presentation

Generating Permutations and Combinations

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Generating Permutations and Combinations • “Traveling Salesman Problem” – A salesman must visit 6 cities; what’s the best order in which to visit them? • Assume real road distances that are not uniform….How many orders (permutations) exist? 1 6 2 3 5 4

  2. Generating Permutations and Combinations • Some numbers from the set • {x1, x2, x3, x4, x5, x6} • Add up to 100….find which ones. • How? • Find all of the subsets of this set…or, the power set. There are 2n possibilities.

  3. Generating Permutations and Combinations • A laboratory has 95 employees. A group of 12 of them with a particular set of 25 skills is needed for a project. How do we select them? • Theorem 2: There are C(n+r-1,r) r-combinations from a set with n elements when repetition of elements is allowed

  4. Generating Permutations • To generate all of the permutations of a set… • Place the elements of the set in one-to-one correspondence with the set {1, 2, 3…n} • List the permutations of the set of elements by generating the permutations of the n integers, then replacing them with the corresponding set elements. • Procedure for this based on: • Lexicographic ordering: Permutations ordered based on precedence: a1, a2,… anprecedes b1, b2,… bn if for some k from 1 to n, a1= b1, a2= b2,… but ak< bk.

  5. Lexicographic Ordering • Generate the permutations of the integers 1, 2, 3 in lexicographic order. • {1, 2, 3} • 123 • 132 • 213 • 231 • 312 • 321

  6. Lexicographic Ordering • What is the lexicographic ordering of the following members of the set • {1, 2, 3, 4, 5}?? • 52143 31425 12543 31245 • What is the permutation that follows 52143? • 52144? • NO!!!! This is not a permutation.

  7. Lexicographic Ordering • What is the next after 52143 in lexicographic ordering of the set • {1, 2, 3, 4, 5}?? • Begin by swapping the last two elements: 52134…. But this is smaller • Rearrange the last THREE elements: 52431, 52314, 52413, 52341….which is next in order? • 52314 < 52341 < 52413 < 52431 • So…52314.

  8. Generating Next Largest • See Algorithm 1, Page 346

  9. Generating Combinations • To generate all of the combinations of a set… • Since a combination is just a subset, use the correspondence between the subsets of the set {1, 2, 3…n} and the bit string of length n. • There are 2n subsets • Example: Find the next largest 2-combination of {1, 2, 3, 4} after {2, 3}. • {2,4}

  10. Generating Combinations • Example: Find the next largest 4 -combination of {1, 2, 3, 4, 5, 6} after {1, 2, 5, 6}. • {1, 3, 5, 6} • Example: Find the next largest bit string after 101011 • 101100 • See algorithm 2, page 347, and algorithm 3, page 348.

  11. Homework • Page 348: 1, 3, 5, 7

More Related