python - Arrange strings for maximum overlap -


let's have set of strings:

strings = {'qqq', 'eqq', 'qqw', 'www', 'qww', 'wwe', 'eee', 'eeq', 'wee', 'qwe'} 

how write algorithm arranges strings such overlap maximally? know 1 way of arranging them follows:

qww  www   wwe    wee     eee      eeq       eqq        qqq         qqw          qwe 

however, found above result brute-force solution. there cleverer way of doing this?

this called shortest superstring problem , np complete.

you might interested in approaches in paper approximation algorithms shortest common superstring problem jonathan turner.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -