# Difference between revisions of "Chapter 9"

Jump to navigation
Jump to search

Line 3: | Line 3: | ||

===Permutations=== | ===Permutations=== | ||

− | :[[9.1]] | + | :[[9.1]]. A ''derangement'' is a permutation <math>p</math> of <math>{1, . . . , n}</math> such that no item is in its proper position, that is, <math>p_i 6= i</math> for all <math>1 \leq i \leq n</math>. Write an efficient backtracking program with pruning that constructs all the derangements of <math>n</math> items. |

+ | [[9.1|Soluiton]] | ||

− | :9.2 | + | :9.2. ''Multisets'' are allowed to have repeated elements. A multiset of n items may thus have fewer than <math>n!</math> distinct permutations. For example, {1, 1, 2, 2} has only six distinct permutations: [1, 1, 2, 2], [1, 2, 1, 2], [1, 2, 2, 1], [2, 1, 1, 2], [2, 1, 2, 1], and [2, 2, 1, 1]. Design and implement an efficient algorithm for constructing all permutations of a multiset. |

− | :[[9.3]] | + | :[[9.3]]. For a given a positive integer <math>n</math>, find all permutations of the <math>2n</math> elements of the multiset <math>S = {1, 1, 2, 2, 3, 3, . . . , n, n}</math> such that for each integer from 1 to <math>n</math> the number of intervening elements between its two appearances is equal to value of the element. For example, when <math>n = 3</math> the two possible solutions are [3, 1, 2, 1, 3, 2] and [2, 3, 1, 2, 1, 3]. |

+ | [[9.3|Solution]] | ||

− | :9.4 | + | :9.4. Design and implement an algorithm for testing whether two graphs are isomorphic. The graph isomorphism problem is discussed in Section 19.9 (page 610). With proper pruning, graphs on hundreds of vertices can be tested in a reasonable time. |

− | :[[9.5]] | + | :[[9.5]]. The set <math>{1, 2, 3, ..., n}</math> contains a total of <math>n!</math> distinct permutations. By listing and labeling all of the permutations in ascending lexicographic order, we get the following sequence for <math>n = 3</math>: |

− | + | <center><math>[123, 132, 213, 231, 312, 321]</math></center> | |

+ | :Give an efficient algorithm that returns the <math>k</math>th of <math>n!</math> permutations in this see quence, for inputs <math>n</math> and <math>k</math>. For efficiency it should not construct the first <math>k - 1</math permutations in the process. | ||

+ | [[9.5|Solution]] | ||

===Backtracking=== | ===Backtracking=== |

## Revision as of 21:08, 13 September 2020

## Contents

# Combinatorial Search

### Permutations

- 9.1. A
*derangement*is a permutation of such that no item is in its proper position, that is, for all . Write an efficient backtracking program with pruning that constructs all the derangements of items.

- 9.2.
*Multisets*are allowed to have repeated elements. A multiset of n items may thus have fewer than distinct permutations. For example, {1, 1, 2, 2} has only six distinct permutations: [1, 1, 2, 2], [1, 2, 1, 2], [1, 2, 2, 1], [2, 1, 1, 2], [2, 1, 2, 1], and [2, 2, 1, 1]. Design and implement an efficient algorithm for constructing all permutations of a multiset.

- 9.3. For a given a positive integer , find all permutations of the elements of the multiset such that for each integer from 1 to the number of intervening elements between its two appearances is equal to value of the element. For example, when the two possible solutions are [3, 1, 2, 1, 3, 2] and [2, 3, 1, 2, 1, 3].

- 9.4. Design and implement an algorithm for testing whether two graphs are isomorphic. The graph isomorphism problem is discussed in Section 19.9 (page 610). With proper pruning, graphs on hundreds of vertices can be tested in a reasonable time.

- 9.5. The set contains a total of distinct permutations. By listing and labeling all of the permutations in ascending lexicographic order, we get the following sequence for :

- Give an efficient algorithm that returns the th of permutations in this see quence, for inputs and . For efficiency it should not construct the first <math>k - 1</math permutations in the process.

### Backtracking

- 9.6

- 9.8

- 9.10

- 9.12

- 9.14

### Games and Puzzles

- 9.16

- 9.18

- 9.20

### Combinatorial Optimization

- 9.22

- 9.24

- 9.26

### Interview Problems

- 9.28

- 9.28

- 9.30

- 9.32

Back to Chapter List