4

Cross post here

A word path means the last character of the last word is same to the first character of the next word.And the path have no duplicated word.If I have $55$ words,I can find it with this method.

### Build a graph

```
SeedRandom[2]
string = Select[ToLowerCase[RandomSample[DictionaryLookup[]]],
3 < StringLength[#] < 5 &];
g = RelationGraph[StringTake[#, -1] == StringTake[#2, 1] &,
string[[;; 55]], VertexLabels -> "Name"]
```

### Find a longest word path by Jason's answer here

```
allPaths =
FindPath[g, #2, #1, Infinity, All] & @@@
Subsets[VertexList[g], {2}] // Apply[Join];
First[TakeLargestBy[allPaths, Length@Union@# &, 1]]
```

`{calm,muir,reef,fray,yaws,seed,deaf,fnma,axis,stow,waft,tint,trig,good,duns,sill,loge,etch,hill,lath,howl}`

Well I have to say this is a very very slow solution.I even cannot find more than $60$ words.Actually I want to find `Length[DictionaryLookup[]]=92518`

words. It seem I still have a long way to go.Do any suggestion can give?

This is probably obvious, but in order to be precise I am going to ask anyway -- I assume the path does not have loops (cannot intersect itself)? – Anton Antonov – 2017-06-01T19:18:24.087

@AntonAntonov Yes,the expected path have no loops. – yode – 2017-06-01T19:42:30.603

One solution is to use a branch-and-bound algorithm design. At each step (branching node) we look at smaller sub-graphs and have heuristics for selecting the sub-graphs that would be more likely to produce longer paths.

– Anton Antonov – 2017-06-02T14:08:17.363While the final path will not have loops, the complete graph is cyclical. Look up the "Approximation" section here: https://en.wikipedia.org/wiki/Longest_path_problem I think the best solution will not only use graph theory, but will also use the understanding of the language and problem itself. E.g. some letters have an extremely low probability of survivorship, others have much higher. Many words begin and end with the same letters, which means that your question is guaranteed to have multiple answers as those words get interchanged.

– Gregory Klopper – 2017-06-15T15:04:45.873@GregoryKlopper Thanks.And I just want to find "a" longest path(though the longest path have many interchanged case maybe.) – yode – 2017-06-15T16:40:29.850