資料結構與演算法(A)
國立臺灣大學 2022 · 考試 · 22 題 · 限時 100 分
整卷連續作答,作答時答案與解析隱藏;按「交卷」後揭曉正解、標準解析並自動批改(申論/計算題不計分,供自行對照)。
- 第 1 題選擇
For each of the following algorithms in the next five problems, what is the tightest asymptotic upper bound for its runtime complexity for numbers? Please use the following table of (A)-(E) choices when answering.
(A) (B) (C) (D) (E) (3 points) Selection sort: expected time?
- 第 2 題選擇
For each of the following algorithms in the next five problems, what is the tightest asymptotic upper bound for its runtime complexity for numbers? Please use the following table of (A)-(E) choices when answering.
(A) (B) (C) (D) (E) (3 points) Merge sort: expected time?
- 第 3 題選擇
For each of the following algorithms in the next five problems, what is the tightest asymptotic upper bound for its runtime complexity for numbers? Please use the following table of (A)-(E) choices when answering.
(A) (B) (C) (D) (E) (3 points) MAX_HEAPIFY for a max-heap: expected time?
- 第 4 題選擇
For each of the following algorithms in the next five problems, what is the tightest asymptotic upper bound for its runtime complexity for numbers? Please use the following table of (A)-(E) choices when answering.
(A) (B) (C) (D) (E) (3 points) Quick sort: worst-case time?
- 第 5 題選擇
For each of the following algorithms in the next five problems, what is the tightest asymptotic upper bound for its runtime complexity for numbers? Please use the following table of (A)-(E) choices when answering.
(A) (B) (C) (D) (E) (3 points) Bucket sort when there are buckets: expected time?
- 第 6 題選擇
(5 points) Which of the following is NOT an in-place sorting algorithm (in their standard implementations)?
- 第 7 題選擇
(5 points) In a max-heap stored in an array, after these 6 numbers have been inserted in this exact sequence: , what is the value of the node at index 2 (with the root being the node at index 1)?
- 第 8 題選擇
(5 points) Following the previous problem, what is the value of the left child of the node with value 3?
- 第 9 題選擇
(5 points) Consider an array of 8 elements being sorted using quicksort. It has just finished the first pass of partitioning and pivot swapping, thus changing the original array into the following array:
How many elements could have been the pivot?
- 第 10 題選擇
(5 points) Consider an integer array of size with elements , where the first elements are positive and the other elements are negative. The following algorithm calculates correctly by calling . What loop invariant is maintained for the while loop of the algorithm?
COMPUTE-P(A, len) 1 if A[1] < 0 return 0 2 left = 1, right = len 3 while left < right 4 m = ceiling((left + right) / 2) 5 if A[m] > 0 6 left = m 7 else 8 right = m - 1 9 return left - 第 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? - 第 12 題選擇
(5 points) Which of the following statement has been proved to be true?
- 第 13 題選擇
(5 points) Consider a hash table with entries with a hash function that can uniformly dispatch items to those entries. Which property below ensures that a successful search can be done in ?
- 第 14 題選擇
(5 points) Consider a red-black tree with internal nodes, where is even. At most how many of them can be a black node with one red child?
- 第 15 題選擇
(5 points) In the red-black tree with 26 nodes that reaches the solution of the problem above, what is the maximum height of the tree? A tree with one node is assumed to have height 1.
- 第 16 題選擇
(5 points) Dynamic programming can be used to solve the matrix-chain multiplication problem. Suppose we hope to compute the matrix product with the matrix dimensions as follows.
matrix dimension Let be the minimum number of scalar multiplications needed to compute the matrix . What is ?
- 第 17 題選擇
(5 points) What is the time complexity of finding the minimum number of scalar multiplications needed for using dynamic programming?
- 第 18 題選擇
(5 points) When using Dijkstra's algorithm to solve the single-source shortest problem for a graph having vertices and edges, which is INCORRECT?
- 第 19 題選擇
(5 points) Consider the following undirected graph . Let be the minimum spanning tree (MST) of the graph. Which is INCORRECT?
Vertices with edges and weights:
- 第 20 題選擇
(5 points) Given a graph with the adjacent matrix with an matrix. The following algorithm can compute the All-Pairs Shortest Path of .
FLOYD-WARSHALL'(W) 1 D = W 2 for k = 1, 2, ..., n 3 for i = 1, 2, ..., n 4 for j = 1, 2, ..., n 5 d_ij = min(d_ij, d_ik + d_kj)What is the SPACE complexity of this algorithm?
- 第 21 題選擇
(5 points) When using the Edmonds-Karp algorithm to find the maximum flow of a flow network , which is CORRECT?
- 第 22 題選擇
(5 points) Consider a fractional knapsack problem of 6 items. The -th item is worth dollars and weighs pounds.
item 1 2 3 4 5 6 pounds 4 2 8 5 5 8 dollars 3 8 16 7 9 20 Suppose that at most pounds can be carried in the knapsack. The sequence of picking the items is