I have a list of strings and I want to find the shortest unique way to identify them. This is a bit like autocomplete, but for this set there will always be the shortest identifiable way.
As an example.
PA for Paddington
PE for Penryn
PLO for Plymouth
PLP for Plympton
PO for Portsmouth
Q for Quebec
I have several thousand names (these are not cities, but program names).
I need a relatively short sequence that will be ok (for the above list, both the key and the value are ok).
Any methods / algorithms for this would be helpful.
I know that I will have to code it (using PHP), but as long as I understand the algorithm, I am happy.
I think I need to build a value tree while they are standing, and then start navigating this tree one character at a time, ignoring sequences that have one option (for example, L and Y in Plymouth / Plympton).
So, starting with Q in Quebec, I would find that all the way through the tree, all subsequent letters are used only once, so Q is enough at this stage.
source
share