The Most Efficient Algorithm to Find First Prefix-Match From a Sorted String Array?

前端 未结 8 802
春和景丽
春和景丽 2021-01-31 00:27

Input:

1) A huge sorted array of string SA;

2) A prefix string P;

Output:

The index of the first string matching the input prefix if any. If ther

8条回答
  •  自闭症患者
    2021-01-31 00:37

    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.

提交回复
热议问题