Câu hỏi phỏng vấn Strings
Câu hỏi

What are the main differences between the Knuth-Morris-Pr...

Câu trả lời

The main differences between the Knuth-Morris-Pratt (KMP) and Boyer-Moore (BM) string search algorithms are:

  1. Scanning direction: KMP scans the text from left to right, while BM scans from right to left[3][5].

  2. Preprocessing: Both algorithms preprocess the pattern, but in different ways. KMP builds a prefix table to avoid comparing characters that are known to match based on previous comparisons[1][2]. BM uses a shift table to determine how far to shift the pattern after a mismatch[1][4].

  3. Performance: In the worst case, KMP has a guaranteed linear time complexity of O(m+n), where m is the pattern length and n is the text length[3]. BM can be faster than KMP on certain inputs that allow skipping many characters, but it has a worst-case complexity of O(nm)[3][4]. So KMP is more reliable, while BM can be faster or slower depending on the input[3].

  4. Alphabet size: KMP works well with small alphabets (e.g., DNA bases) because...

expert

expert

Gợi ý câu hỏi phỏng vấn

senior

What are some limitations of Ropes?

senior

Why is char[] preferred over String for passwords?

junior

What is strings mutability and immutability?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào