← 回題庫

卷別

資料結構與演算法

選擇

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

考科演算法

(4 points) Let SS be a stack containing n+1n+1 coefficients a0,a1,…,ana_0, a_1, \dots, a_n, where n≥1n \ge 1, ana_n is at the top of the stack, and a0a_0 is at the bottom. The following algorithm computes f(x)=∑i=0naixif(x) = \sum_{i=0}^{n} a_i x^i. Identify the missing expression □\square in the pseudocode.

POLY(S, x):
1   while S.size ≥ 2
2       u = S.pop()
3       v = S.pop()
4       S.push(□)
5   return S.pop()
  • (A)
    v⋅x+uv \cdot x + u
  • (B)
    u⋅x+vu \cdot x + v
  • (C)
    v⋅u+xv \cdot u + x
  • (D)
    u⋅u+v⋅xu \cdot u + v \cdot x
  • (E)
    None of the other choices.

標準解析

AI 已複查