0

I am reading about permutation generation and relationship with Travelling Salesman Problem in Introduction to design and analysis of algorithms.

Here author mentioned as below

We can insert n in the previously generated permutations either left to right or right to left. It turns out that it is beneficial to start with inserting n into 12 . . . (n − 1) by moving right to left and then switch direction every time a new permutation of {1, . . . , n − 1} needs to be processed. The advantage of this order of generating permutations stems from the fact that it satisfies the minimal-change requirement: each permutation can be obtained from its immediate predecessor by exchanging just two elements in it.

If such permutations are generated by a minimal-change algorithm, we can compute the length of a new tour from the length of its predecessor in constant rather than linear time.

My question on above text: How can we calculate length form predecessor in constant time if we use minimum change algorithm? If possible, please give a simple example with n=3.

tobias_k
  • 81,265
  • 12
  • 120
  • 179
venkysmarty
  • 11,099
  • 25
  • 101
  • 184

1 Answers1

1

Let's say you swap element b with element e, oddly chosen letters because we suppose b is the middle element of a path a->b->c and e is the middle element of a path d->e->f.

4 edges disappear, they are replaced by 4 new edges. The ones that disappear are the ones that connect b and e to their old neighbours. The new ones are a->e, e->c, d->b and b->f.

So the new total length is

old - d(a, b) - d(b, c) - d(d, e) - d(e, f) + d(a, e) + d(e, c) + d(d, b) + d(b, f)
harold
  • 61,398
  • 6
  • 86
  • 164
  • can you please eloborate. Not able to follow above explanation. Thanks – venkysmarty Jan 09 '15 at 09:32
  • @venkysmarty ok but is there anything in particular you don't follow about it? – harold Jan 09 '15 at 09:34
  • To put it differently - the change in cost is only local. The change of cost can be calculated given the graph only; if the current cost of a tour is known, this change cost can be added to obtain the cost of a new tour. – Codor Jan 09 '15 at 10:24
  • @ harold: how we are using previous permutation and achieving constant time – venkysmarty Jan 09 '15 at 10:24
  • @venkysmarty the previous path has a->b->c and d->e->f in it. The new path has b and e swapped, so it has a->e->c and d->b->f in it. The calculation I showed calculates the new length from the old length, and it is obviously a constant time calculation. – harold Jan 09 '15 at 10:27