Java indexOf function more efficient than Rabin-Karp? Search Efficiency of Text

后端 未结 7 517
面向向阳花
面向向阳花 2020-12-20 11:47

I posed a question to Stackoverflow a few weeks ago about a creating an efficient algorithm to search for a pattern in a large chunk of text. Right now I am using the St

7条回答
  •  Happy的楠姐
    2020-12-20 12:36

    For this kind of search, Knuth-Morris-Pratt may perform better. In particular if the sub-string doesn't just repeat characters, then KMP should outperform indexOf(). Worst case (string of all the same characters) it will be the same.

提交回复
热议问题