search List for string .StartsWith()

后端 未结 10 1749
终归单人心
终归单人心 2021-01-19 00:13

I have a

List

with 1500 strings. I am now using the following code to pull out only string that start with the string prefix

10条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-19 00:29

    Thus 1500 is not really a huge number binary search on sorted list would be enough probably. Nevertheless most efficient algorithms for prefix search are based on the data structure named Trie or Prefix Tree. See: http://en.wikipedia.org/wiki/Trie

    Following picture demonstrates the idea very briefly: enter image description here

    For c# implementation see for instance .NET DATA STRUCTURES FOR PREFIX STRING SEARCH AND SUBSTRING (INFIX) SEARCH TO IMPLEMENT AUTO-COMPLETION AND INTELLI-SENSE

提交回复
热议问题