The.Algorithm.Design.Manual.Springer-Verlag.1998
The.Algorithm.Design.Manual.Springer-Verlag.1998 The.Algorithm.Design.Manual.Springer-Verlag.1998
Constructing All Permutations Next: Constructing All Paths in Up: Backtracking Previous: Constructing All Subsets Constructing All Permutations To design a suitable state space for representing permutations, we start by counting them. There are n distinct choices for the value of the first element of a permutation of . Once we have fixed this value of , there are n-1 candidates remaining for the second position, since we can have any value except (repetitions are forbidden). Repeating this argument yields a total of distinct permutations. This counting argument suggests a suitable representation. To construct all n! permutations, set up an array/vector A of n cells. The set of candidates for the ith position will be the set of elements that have not appeared in the (i-1) elements of the partial solution, corresponding to the first i-1 elements of the permutation. To use the notation of the general backtrack algorithm, . The vector A contains a full solution whenever k = n+1. This representation generates the permutations of in the following order: The problem of generating permutations is more thoroughly discussed in Section . Algorithms Mon Jun 2 23:33:50 EDT 1997 file:///E|/BOOK/BOOK2/NODE86.HTM [19/1/2003 1:29:26]
Constructing All Paths in a Graph Next: Search Pruning Up: Backtracking Previous: Constructing All Permutations Constructing All Paths in a Graph Enumerating all the simple paths from to t through a given graph is a somewhat more complicated problem than listing permutations or subsets. Unlike the earlier problems, there is no explicit formula that counts the number of solutions as a function of the number of edges or vertices, because the number of paths depends upon the structure of the graph. Figure: The search tree enumerating all simple paths from vertex 1 in the graph Since the starting point of any path from to t is always , must be . The set of possible candidates for the second position are the vertices v such that (,v) is an edge of the graph, for the path wanders from vertex to vertex using edges to define the legal steps. In general, consists of the set of vertices adjacent to that have not been used in the partial solution A. We can report a successful path whenever . The solution vector A must have room for all n vertices, although most paths are likely to be shorter than this. Figure shows the search tree giving all paths from a particular vertex in an example graph. Algorithms Mon Jun 2 23:33:50 EDT 1997 file:///E|/BOOK/BOOK2/NODE87.HTM [19/1/2003 1:29:26]
- Page 221 and 222: The Friendship Graph friendship gra
- Page 223 and 224: Data Structures for Graphs linked t
- Page 225 and 226: War Story: Getting the Graph ``Well
- Page 227 and 228: Traversing a Graph Next: Breadth-Fi
- Page 229 and 230: Breadth-First Search Next: Depth-Fi
- Page 231 and 232: Depth-First Search Next: Applicatio
- Page 233 and 234: Depth-First Search Next: Applicatio
- Page 235 and 236: Connected Components Next: Tree and
- Page 237 and 238: Two-Coloring Graphs Next: Topologic
- Page 239 and 240: Topological Sorting Next: Articulat
- Page 241 and 242: Modeling Graph Problems Next: Minim
- Page 243 and 244: Modeling Graph Problems good line s
- Page 245 and 246: Minimum Spanning Trees ● Prim's A
- Page 247 and 248: Prim's Algorithm inserted edge (x,y
- Page 249 and 250: Kruskal's Algorithm a tree of weigh
- Page 251 and 252: Dijkstra's Algorithm Next: All-Pair
- Page 253 and 254: All-Pairs Shortest Path Next: War S
- Page 255 and 256: War Story: Nothing but Nets Next: W
- Page 257 and 258: War Story: Nothing but Nets ``You a
- Page 259 and 260: War Story: Dialing for Documents Ne
- Page 261 and 262: War Story: Dialing for Documents If
- Page 263 and 264: War Story: Dialing for Documents CO
- Page 265 and 266: Exercises Next: Implementation Chal
- Page 267 and 268: Exercises Prove the statement or gi
- Page 269 and 270: Backtracking report it. kth element
- Page 271: Constructing All Subsets Next: Cons
- Page 275 and 276: Search Pruning Next: Bandwidth Mini
- Page 277 and 278: Bandwidth Minimization immediately
- Page 279 and 280: War Story: Covering Chessboards Nex
- Page 281 and 282: War Story: Covering Chessboards att
- Page 283 and 284: Heuristic Methods Mon Jun 2 23:33:5
- Page 285 and 286: Simulated Annealing Return S then u
- Page 287 and 288: Traveling Salesman Problem Next: Ma
- Page 289 and 290: Independent Set Next: Circuit Board
- Page 291 and 292: Neural Networks Next: Genetic Algor
- Page 293 and 294: Genetic Algorithms Next: War Story:
- Page 295 and 296: War Story: Annealing Arrays Next: P
- Page 297 and 298: War Story: Annealing Arrays optimal
- Page 299 and 300: Parallel Algorithms Next: War Story
- Page 301 and 302: War Story: Going Nowhere Fast Next:
- Page 303 and 304: Exercises Next: Implementation Chal
- Page 305 and 306: Problems and Reductions Next: Simpl
- Page 307 and 308: Simple Reductions Next: Hamiltonian
- Page 309 and 310: Hamiltonian Cycles Next: Independen
- Page 311 and 312: Independent Set and Vertex Cover pr
- Page 313 and 314: Clique and Independent Set These la
- Page 315 and 316: Satisfiability Mon Jun 2 23:33:50 E
- Page 317 and 318: The Theory of NP-Completeness Next:
- Page 319 and 320: 3-Satisfiability where for , , , an
- Page 321 and 322: Integer Programming Next: Vertex Co
Constructing All Permutations<br />
Next: Constructing All Paths in Up: Backtracking Previous: Constructing All Subsets<br />
Constructing All Permutations<br />
To design a suitable state space for representing permutations, we start by counting them. <strong>The</strong>re are n<br />
distinct choices for the value of the first element of a permutation of . Once we have fixed this<br />
value of , there are n-1 candidates remaining for the second position, since we can have any value<br />
except (repetitions are forbidden). Repeating this argument yields a total of distinct<br />
permutations.<br />
This counting argument suggests a suitable representation. To construct all n! permutations, set up an<br />
array/vector A of n cells. <strong>The</strong> set of candidates for the ith position will be the set of elements that have<br />
not appeared in the (i-1) elements of the partial solution, corresponding to the first i-1 elements of the<br />
permutation. To use the notation of the general backtrack algorithm, . <strong>The</strong> vector A<br />
contains a full solution whenever k = n+1. This representation generates the permutations of in<br />
the following order:<br />
<strong>The</strong> problem of generating permutations is more thoroughly discussed in Section .<br />
<strong>Algorithm</strong>s<br />
Mon Jun 2 23:33:50 EDT 1997<br />
file:///E|/BOOK/BOOK2/NODE86.HTM [19/1/2003 1:29:26]