<p>This is intended to be a more concrete, easily expressable form of my earlier question.</p>

<p>Take a list of words from a dictionary with common letter length.<br>
How to reorder this list tto keep as many letters as possible common between adjacent words?  </p>

<p>Example 1:</p>

<pre><code>AGNI, CIVA, DEVA, DEWA, KAMA, RAMA, SIVA, VAYU
reorders to:  
AGNI, CIVA, SIVA, DEVA, DEWA, KAMA, RAMA, VAYU  
</code></pre>

<p>Example 2:</p>

<pre><code>DEVI, KALI, SHRI, VACH
reorders to:
DEVI, SHRI, KALI, VACH
</code></pre>

<p>The simplest algorithm seems to be:  Pick anything, then search for the shortest distance?<br>
However, DEVI->KALI  (1 common) is equivalent to DEVI->SHRI (1 common)<br>
Choosing the first match would result in fewer common pairs in the entire list (4 versus 5). </p>

<p>This seems that it should be simpler than full TSP? </p>

This can be done with a recursive approach. Pseudo-code:
```
```
Start with one of the words, call it w
FindNext(w, l) // l = list of words without w
  Get a list l of the words near to w
  If only one word in list
    Return that word
  Else
    For every word w' in l do FindNext(w', l') //l' = l without w'
```
```
You can add some score to count common pairs and to prefer "better" lists.