卷別
資料結構與演算法(A)
選擇國立臺灣大學 2022 · 考試 · 第 11 題
考科演算法
(5 points) Consider a string of length , e.g., cbaabcba. We want to add the smallest number of characters to the front of the string to make it a palindrome, e.g., abcbaabcba. This problem can be solved by first concatenating the string with its inverse with a delimiter #, e.g. cbaabcba#abcbaabc. Then, run the pre-processing routine of the Knuth-Morris-Pratt algorithm on the new string of length to get a failure function , which computes the length of the longest prefix of the string that is also a suffix. After running the pre-processing algorithm, how can we calculate the smallest number of characters that should be added to the front of the original string to make a palindrome?
- (A)
- (B)
- (C)
- (D)
- (E)none of the other choices