Presentation is loading. Please wait.

Presentation is loading. Please wait.

Generating Permutations and Combinations “Traveling Salesman Problem” – A salesman must visit 6 cities; what’s the best order in which to visit them? Assume.

Similar presentations


Presentation on theme: "Generating Permutations and Combinations “Traveling Salesman Problem” – A salesman must visit 6 cities; what’s the best order in which to visit them? Assume."— 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? 4 23 1 5 6

2 Some numbers from the set {x 1, x 2, x 3, x 4, x 5, x 6 } Add up to 100….find which ones. How? Find all of the subsets of this set…or, the power set. There are 2 n possibilities. Generating Permutations and Combinations

3 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 Generating Permutations and Combinations

4 Generating Permutations To generate all of the permutations of a set… 1.Place the elements of the set in one-to-one correspondence with the set {1, 2, 3…n} 2.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: a 1, a 2,… a n precedes b 1, b 2,… b n if for some k from 1 to n, a 1 = b 1, a 2 = b 2,… but a k < b k.

5 Lexicographic Ordering Generate the permutations of the integers 1, 2, 3 in lexicographic order. {1, 2, 3} 123132213231312321

6 Lexicographic Ordering What is the lexicographic ordering of the following members of the set {1, 2, 3, 4, 5}?? 52143314251254331245 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}?? 1.Begin by swapping the last two elements: 52134…. But this is smaller 2.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 2 n 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


Download ppt "Generating Permutations and Combinations “Traveling Salesman Problem” – A salesman must visit 6 cities; what’s the best order in which to visit them? Assume."

Similar presentations


Ads by Google