← 回題庫

卷別

資料結構與演算法

選擇

國立臺灣大學 2026 · 考試 · 第 8 題

考科演算法

(4 points) Given the string S=wuwvwuuvS = \texttt{wuwvwuuv}, compute the Knuth–Morris–Pratt failure function π[0…7]\pi[0 \dots 7], where π[i]\pi[i] is the length of the longest proper prefix of S[0…i]S[0 \dots i] which is also a suffix of S[0…i]S[0 \dots i]. Which of the following is correct?

  • (A)
    π=[0,0,1,0,1,2,0,0]\pi = [0, 0, 1, 0, 1, 2, 0, 0]
  • (B)
    π=[0,0,1,0,1,2,2,3]\pi = [0, 0, 1, 0, 1, 2, 2, 3]
  • (C)
    π=[0,1,0,1,2,0,1,2]\pi = [0, 1, 0, 1, 2, 0, 1, 2]
  • (D)
    π=[0,0,0,1,1,2,3,3]\pi = [0, 0, 0, 1, 1, 2, 3, 3]
  • (E)
    π=[0,0,1,1,2,2,2,3]\pi = [0, 0, 1, 1, 2, 2, 2, 3]

標準解析

AI 已複查