← 回題庫

資料結構與演算法

國立臺灣大學 2026 · 考試 · 25 題 · 限時 100 分

剩餘 1:40:00已答 0/25

整卷連續作答,作答時答案與解析隱藏;按「交卷」後揭曉正解、標準解析並自動批改(申論/計算題不計分,供自行對照)。

  1. 第 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()
    
  2. 第 2 題選擇

    (4 points) For positive functions f(n)f(n) and g(n)g(n) on N\mathbb{N}. If f(n)=O(g(n))f(n) = O(g(n)) and f(n)=Ω(1)f(n) = \Omega(1), how many of the following statements are true?

    • g(n)=Ω(f(n))g(n) = \Omega(f(n))
    • f(n)⋅log⁡(1+f(n))=O(g(n)⋅log⁡(1+g(n)))f(n) \cdot \log(1 + f(n)) = O\big(g(n) \cdot \log(1 + g(n))\big)
    • 2f(n)=O(2g(n))2^{f(n)} = O\big(2^{g(n)}\big)
    • (f(n))k=O((g(n))k)(f(n))^k = O\big((g(n))^k\big) for any 0<k<10 < k < 1
  3. 第 3 題選擇

    (4 points) In 2022, DeepMind's AlphaTensor discovered a new state-of-the-art strategy for multiplying two 4×44 \times 4 matrices using only 47 multiplications (under a special arithmetic) instead of the original 49. By integrating this method into a standard divide-and-conquer framework, the complexity of multiplying two n×nn \times n matrices is reduced to O(nk)O(n^k). Compute kk based on the above information for the tightest upper bound.

  4. 第 4 題選擇

    (4 points) Which of the following □\square generates a uniformly random permutation of an array AA of size nn in place, assuming that Random(ℓ,r)\textsc{Random}(\ell, r) returns an integer chosen uniformly at random from {ℓ,ℓ+1,…,r−1,r}\{\ell, \ell+1, \dots, r-1, r\}?

    RANDOM-PERMUTE(A):
    1   for i = 1 to n
    2       □
    3       if a ≤ b
    4           swap A[i] with A[RANDOM(a, b)]
    
  5. 第 5 題選擇

    (4 points) Which of the following statements is known to be true?

  6. 第 6 題選擇

    (4 points) How many of the statements below are known to be true?

    • Every problem in NP is polynomial-time reducible to some NP-hard problem.
    • Every problem in NP is polynomial-time reducible to some NP-complete problem.
    • Every problem in NP is polynomial-time reducible to some problem solvable within polynomial time.
    • Every problem in NP is polynomial-time reducible to some problem solvable within exponential time.
  7. 第 7 題選擇

    (4 points) A company needs to assign 3 workers to 3 tasks. Each worker can perform only the tasks listed below:

    • Worker W1W_1: Tasks T1,T2T_1, T_2
    • Worker W2W_2: Task T1T_1
    • Worker W3W_3: Tasks T2,T3T_2, T_3

    Each worker can be assigned to at most one task, and each task to at most one worker. Which of the following statements is true?

  8. 第 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?

  9. 第 9 題選擇

    (4 points) Which property of the root of unity Wn=e2πi/nW_n = e^{2\pi i / n}, where nn is a power of 2, allows the Cooley–Tukey fast-fourier transform algorithm to achieve its speedup in time complexity?

  10. 第 10 題選擇

    (4 points) Consider an array [4,5,1,10,2,7][4, 5, 1, 10, 2, 7], if Build-Max-Heap\textsc{Build-Max-Heap} (bottom-up heapify) is performed, a process that converts the array into a max-heap by adjusting elements starting from the bottom non-leaf nodes and working up to the root. What is the resulting array?

  11. 第 11 題選擇

    (4 points) Which pivot selection strategy in Quicksort is usually the most effective at avoiding the O(n2)O(n^2) worst-case runtime across arbitrary input distributions?

  12. 第 12 題選擇

    (4 points) Bucket sort has an expected linear runtime, O(n)O(n), under which of the following fundamental conditions?

  13. 第 13 題選擇

    (4 points) Which algorithm guarantees finding the median (the n/2n/2-th order statistic) of an array of nn elements in O(n)O(n) worst-case time?

  14. 第 14 題選擇

    (4 points) A queue QQ is implemented using two stacks SinS_{\text{in}} and SoutS_{\text{out}} as follows. If each Push\textsc{Push} or Pop\textsc{Pop} with the stack has a cost of Θ(1)\Theta(1), what is the amortized cost per operation over a sequence of mm legal queue operations, starting from an empty state with the first operation being Enqueue\textsc{Enqueue}?

    ENQUEUE(Q, x):
    1   PUSH(Q.S_in, x)
    
    DEQUEUE(Q):
    1   if Q.S_out is not empty
    2       return POP(Q.S_out)
    3   while Q.S_in is not empty
    4       PUSH(Q.S_out, POP(Q.S_in))
    5   return POP(Q.S_out)
    
  15. 第 15 題選擇

    (4 points) Most hash table implementations (such as Java's HashMap) resize the underlying array when the load factor exceeds a certain threshold (typically 0.75). Why is this resizing operation important for a hash table that uses separate chaining?

  16. 第 16 題選擇

    (4 points) Assume that there are KK possible keys {1,2,…,K}\{1, 2, \dots, K\} and mm hash table slots {0,1,…,m−1}\{0, 1, \dots, m-1\} with m>1m > 1. In double hashing, the probe sequence is

    h(k,i)=(h1(k)+i h2(k)) mod m.h(k, i) = \big(h_1(k) + i\, h_2(k)\big) \bmod m.

    For a fixed key kk, we want the sequence h(k,0),h(k,1),…h(k, 0), h(k, 1), \dots to visit all mm table slots before repeating, so that insertion succeeds whenever the table is not full. Which of the following conditions is necessary and sufficient for this property (for that key kk)?

  17. 第 17 題選擇

    (4 points) Consider the Binary Search Tree in Figure 1. If node 66 is removed (replacing it with its in-order successor), what is the resulting preorder traversal sequence?

    Figure 1 的二元搜尋樹結構如下:

            56
           /  \
         23    66
        /     /  \
       3     57   72
    
  18. 第 18 題選擇

    (4 points) Which of the following properties is true for some optimal prefix-free binary code and directly justifies the greedy choice made in the Huffman algorithm?

  19. 第 19 題選擇

    (4 points) Consider a dynamic table that: (1) starts empty with capacity 1; (2) doubles its capacity when full; (3) shrinks its capacity by a factor of 1/21/2 when the capacity ≥4\ge 4 and the number of stored elements falls below one quarter of the capacity. Assume that inserting or deleting an element costs 1, and resizing a table of size kk costs Θ(k)\Theta(k). Which statement is true when considering nn insertion and removal operations?

  20. 第 20 題選擇

    (4 points) Consider a red–black tree augmented for dynamic order statistics by storing, at each node xx, the attribute

    x.size=number of nodes in the subtree rooted at x, including x itself.x.\texttt{size} = \text{number of nodes in the subtree rooted at } x, \text{ including } x \text{ itself.}

    Which of the following statements is correct?

  21. 第 21 題選擇

    (4 points) Let TT be a B-tree of minimum degree t≥2t \ge 2. During the deletion of a key kk from an internal node xx, suppose kk is stored in xx at index ii. Which of the following actions correctly preserves all B-tree invariants before the recursive deletion proceeds?

  22. 第 22 題選擇

    (4 points) Let X[1…m]X[1 \dots m] and Y[1…n]Y[1 \dots n] be two sequences. Let L[i][j]L[i][j] denote the length of the longest common subsequence (LCS) of the prefixes X[1…i]X[1 \dots i] and Y[1…j]Y[1 \dots j], and let C[i][j]C[i][j] denote the number of distinct LCSs (distinct sequences, not dynamic programming paths or alignments) of these prefixes. Let C[i][0]=C[0][j]=1C[i][0] = C[0][j] = 1, since the empty sequence is the unique LCS in these cases. Which of the following recurrences correctly computes C[i][j]C[i][j] without double counting identical LCS sequences?

    Here, "without double counting" means that each distinct LCS sequence is counted exactly once, even if it can be obtained from multiple dynamic programming subproblems or alignments. In particular, when multiple subproblems yield LCSs of the same optimal length, any LCS sequence that appears in more than one subproblem must be counted only once.

  23. 第 23 題選擇

    (4 points) Consider the linked-list representation of disjoint sets, where: (1) each set is represented by a linked list; (2) each element stores a pointer to the set's representative; (3) Union(x,y)\textsc{Union}(x, y) appends the shorter list to the longer list (union by weight/size); (4) Find-Set(x)\textsc{Find-Set}(x) runs in O(1)O(1) since the representative pointer. Which of the following statements is correct?

  24. 第 24 題選擇

    (4 points) Let G=(V,E)G = (V, E) be a directed graph represented using adjacency lists without edge weights. We run BFS from a source ss, producing distance labels d[v]d[v] for each reachable vertex vv. Which of the following statements is always true?

  25. 第 25 題選擇

    (4 points) Let G=(V,E)G = (V, E) be a connected, undirected, weighted graph with distinct and positive edge weights. Let A⊆EA \subseteq E be a subset of edges that is contained in some minimum spanning tree of GG. Which of the following statements is always true?