資料結構與演算法
國立臺灣大學 2026 · 考試 · 25 題 · 限時 100 分
整卷連續作答,作答時答案與解析隱藏;按「交卷」後揭曉正解、標準解析並自動批改(申論/計算題不計分,供自行對照)。
- 第 1 題選擇
(4 points) Let be a stack containing coefficients , where , is at the top of the stack, and is at the bottom. The following algorithm computes . Identify the missing expression 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 題選擇
(4 points) For positive functions and on . If and , how many of the following statements are true?
- for any
- 第 3 題選擇
(4 points) In 2022, DeepMind's AlphaTensor discovered a new state-of-the-art strategy for multiplying two 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 matrices is reduced to . Compute based on the above information for the tightest upper bound.
- 第 4 題選擇
(4 points) Which of the following generates a uniformly random permutation of an array of size in place, assuming that returns an integer chosen uniformly at random from ?
RANDOM-PERMUTE(A): 1 for i = 1 to n 2 □ 3 if a ≤ b 4 swap A[i] with A[RANDOM(a, b)] - 第 5 題選擇
(4 points) Which of the following statements is known to be true?
- 第 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 題選擇
(4 points) A company needs to assign 3 workers to 3 tasks. Each worker can perform only the tasks listed below:
- Worker : Tasks
- Worker : Task
- Worker : Tasks
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 題選擇
(4 points) Given the string , compute the Knuth–Morris–Pratt failure function , where is the length of the longest proper prefix of which is also a suffix of . Which of the following is correct?
- 第 9 題選擇
(4 points) Which property of the root of unity , where is a power of 2, allows the Cooley–Tukey fast-fourier transform algorithm to achieve its speedup in time complexity?
- 第 10 題選擇
(4 points) Consider an array , if (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 題選擇
(4 points) Which pivot selection strategy in Quicksort is usually the most effective at avoiding the worst-case runtime across arbitrary input distributions?
- 第 12 題選擇
(4 points) Bucket sort has an expected linear runtime, , under which of the following fundamental conditions?
- 第 13 題選擇
(4 points) Which algorithm guarantees finding the median (the -th order statistic) of an array of elements in worst-case time?
- 第 14 題選擇
(4 points) A queue is implemented using two stacks and as follows. If each or with the stack has a cost of , what is the amortized cost per operation over a sequence of legal queue operations, starting from an empty state with the first operation being ?
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 題選擇
(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 題選擇
(4 points) Assume that there are possible keys and hash table slots with . In double hashing, the probe sequence is
For a fixed key , we want the sequence to visit all 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 )?
- 第 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 題選擇
(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 題選擇
(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 when the capacity 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 costs . Which statement is true when considering insertion and removal operations?
- 第 20 題選擇
(4 points) Consider a red–black tree augmented for dynamic order statistics by storing, at each node , the attribute
Which of the following statements is correct?
- 第 21 題選擇
(4 points) Let be a B-tree of minimum degree . During the deletion of a key from an internal node , suppose is stored in at index . Which of the following actions correctly preserves all B-tree invariants before the recursive deletion proceeds?
- 第 22 題選擇
(4 points) Let and be two sequences. Let denote the length of the longest common subsequence (LCS) of the prefixes and , and let denote the number of distinct LCSs (distinct sequences, not dynamic programming paths or alignments) of these prefixes. Let , since the empty sequence is the unique LCS in these cases. Which of the following recurrences correctly computes 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 題選擇
(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) appends the shorter list to the longer list (union by weight/size); (4) runs in since the representative pointer. Which of the following statements is correct?
- 第 24 題選擇
(4 points) Let be a directed graph represented using adjacency lists without edge weights. We run BFS from a source , producing distance labels for each reachable vertex . Which of the following statements is always true?
- 第 25 題選擇
(4 points) Let be a connected, undirected, weighted graph with distinct and positive edge weights. Let be a subset of edges that is contained in some minimum spanning tree of . Which of the following statements is always true?