4

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

Community
  • 1
  • 1
Konstantin Vladimirov
  • 6,791
  • 1
  • 27
  • 36

1 Answers1

2

I think you'll find more resources expressing this as the longest path problem in a digraph. The longest path formulation of the problem appears to have received more attention than the Euler formulation. Note also that longest path is different than hamiltonian because the former need not span the graph.

Treat each city as a vertex, and put an arc between pairs of vertices that represent a feasible sequence.

It is worth mentioning that longest path is hard to approximate, and it remains NP-complete in very simple graphs: http://en.wikipedia.org/wiki/Longest_path_problem

Here are links to some related papers:

http://link.springer.com/article/10.1007/BF02579454

http://lup.lub.lu.se/luur/download?func=downloadFile&recordOId=957757&fileOId=9\ 65291

Tom Swifty
  • 2,864
  • 2
  • 16
  • 25
  • 1
    There is a problem with this approach. If vertices are city names, then N is about 10000 and O(2^N) is really large. Hard approximation means that even close solution isn't possible at all. On the other hand if vertices are letters, then N is about 26 and O(2^N) seems much better. – Konstantin Vladimirov Oct 10 '13 at 14:44
  • For the Euler formulation, I'm betting that the complexity grows with E, and we have O(E)=O(2^N). However, I can't say for sure. – Tom Swifty Oct 10 '13 at 17:35