I've got a list of strings and I want to find the shortest unique way to identify them. It is a bit like an autocomplete but, for a given set, 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've got several thousand names (they aren't cities, but programmes names).

I need a relatively short sequence that will be in order (for the above list, both the key and value are in order).

Any techniques/algorithms for this would be useful.

I know I'll have to code it (using PHP), but as long as I can understand the algorithm, I'm happy.

I think I have to build a tree of values as they currently stand, then start navigating that tree one character at a time, ignoring sequences that have a single option (the L and Y in Plymouth/Plympton for example).

So, starting with the Q in Quebec, I'd find that all the way through the tree, all subsequent letters are only used once, so Q is enough at that stage.