The Most Efficient Algorithm to Find First Prefix-Match From a Sorted String Array?
If you only want to do this once, use binary search, if on the other hand you need to do it for many different prefixes but on the same string array, building a radix tree can be a good idea, after you've built the tree each look up will be very fast.
It can be done in linear time using a Suffix Tree. Building the suffix tree takes linear time.
This is just a modified bisection search:
- Only check as many characters in each element as are in the search string; and
- If you find a match, keep searching backwards (either linearly or by further bisection searches) until you find a non-matching result and then return the index of the last matching result.