天天看點

字元串搜尋算法

http://dsqiu.iteye.com/blog/1700312

BF(Brute Force)算法

1.思想

2.程式設計實作

暴力算法,又稱樸素算法,是最基本的字元串搜尋算法,當然也是效率最低的算法.

3.時間複雜度

時間複雜度為O(m*n) //m與n分别為2個字元串的長度

4.補充資料

KMP(Knuth-Morris-Pratt)算法 

3.時間空間複雜度

http://www.ruanyifeng.com/blog/2013/05/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm.html

BM(Boyer-Moore)算法

時間複雜度為O(m+n) //m與n分别為2個字元串的長度

http://www.ruanyifeng.com/blog/2013/05/boyer-moore_string_search_algorithm.html

http://www.stoimen.com/blog/2012/04/17/computer-algorithms-boyer-moore-string-search-and-matching/

Sunday算法

在實用方面,KMP算法并不比最簡單的c庫函數strstr()快多少,而BM算法則往往比KMP算法快上3-5倍。

但是BM算法還不是最快的算法,還有一種Sunday算法,它是BM算法的一種改進型。

http://blog.sina.com.cn/s/blog_4b3d71b50100n8vy.html