BF algorithm is simple and rude, but the disadvantage is that there are a lot of backtracking every time the matching is unsuccessful, which leads to low program efficiency. KMP algorithm makes full use of the successful matching results to ensure that the main string cursor does not backtrack, and the mode string cursor backtracks to slide to the right, which greatly improves the efficiency of the program.