To be more precise in problem formulation, let me reformulate it as a "cities" game. Plays two players. Player 1 says some city name, say Moscow
. Player 2 now must say some city name, starting with last letter of previously called city. This letter is W
, so second player says something like Washington
. Player 1 next calls some city, starting with N
as Norilsk
, Player 2 now must say some city name, starting with K
and so forth. One, who can not say city name loses a game.
Now say we have letters a..z
as graph vertices and list of (say 10000) city names as edges. Every edge connects two vertices (like moscow
connects m
and w
) and is oriented m -> w
.
So we now have oriented multigraph.
Task is to find the longest possible cities sequence from given in list. Every city may occur in sequence only once. So task is very close to euler path, but in given graph there may be a lot of euler subgraphs.
My question is how to find maximum path in reasonable time?
I know, that maximum euler subgraph problem is NP-hard. But in my problem graph is very strongly connected and it have a small and fixed number of vertices (like in "cities" game described above). May be it is possible to use it to build some good heuristics?
Also I found some word sequences questions on stackoverflow, but no reasonable answers, because it seems obvious that hamiltonian subgraph in words graph is much harder to find, than euler subgraph in letters graph if words are edges, and all this questions are about hamiltonian, not euler subgraphs.
Will appreciate any useful links, ideas, algorithm descriptions and approaches in any programming language or pseudo-code.
With best regards, Konstantin