Source: http://www.cs.nctu.edu.tw/~chengchc/Course_2011_Spr_ICP/ICP_05_String.pdf