Generating Permutations and Combinations Traveling Salesman Problem A
Generating Permutations and Combinations “Traveling Salesman Problem” – A salesman must visit 6 cities; what’s the best order in which to visit them? 1 2 6 3 5 4 Assume real road distances that are not uniform…. How many orders (permutations) exist?
Generating Permutations and Combinations 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 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) rcombinations from a set with n elements when repetition of elements is allowed
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, … an precedes b 1, b 2, … bn if for some k from 1 to n, a 1= b 1, a 2= b 2, … but ak< bk.
Lexicographic Ordering Generate the permutations of the integers 1, 2, 3 in lexicographic order. {1, 2, 3} 123 132 213 231 312 321
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.
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.
Generating Next Largest See Algorithm 1, Page 346
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}
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 10101100 See algorithm 2, page 347, and algorithm 3, page 348.
Homework Page 348: 1, 3, 5, 7
- Slides: 11