資料結構與演算法(A)
國立臺灣大學 2021 · 考試 · 20 題 · 限時 100 分
整卷連續作答,作答時答案與解析隱藏;按「交卷」後揭曉正解、標準解析並自動批改(申論/計算題不計分,供自行對照)。
- 第 1 題選擇
(5 points) When CAN the worst case of Quicksort occur?
- : Quick Sort where leftmost (or rightmost) element is always chosen as pivot
- : leftmost element is chosen as pivot and array is already sorted in SAME order
- : leftmost element is chosen as pivot and array is already sorted in REVERSE order
- 第 2 題選擇
(5 points) A typical dynamic programming example is the snake sequence. Given a grid of numbers, find the maximum length snake sequence. A snake sequence is made up of adjacent numbers in the grid such that for each number, the number on the right or the number below it is or its value. At location , you can move right or move down if that number is . The length of a snake sequence is defined as the number of moves. Given the following grid ( rows, columns; rows top-to-bottom):
9, 6, 5, 2 8, 7, 6, 5 7, 3, 1, 6 1, 1, 1, 7The maximum LENGTH of snake sequence is?
- 第 3 題選擇
(5 points) 承上題(snake sequence,網格為 列 行)。Time complexity of the above solution is?
- 第 4 題選擇
(5 points) 承 snake sequence 題(網格如下,格座標依題目 定義: 為行方向索引、 為列方向索引,均由 0 起算):
9, 6, 5, 2 8, 7, 6, 5 7, 3, 1, 6 1, 1, 1, 7The last number of the maximum-length snake sequence is?
- 第 5 題選擇
(5 points) 承 snake sequence 題(網格如下,格座標依題目 定義,均由 0 起算):
9, 6, 5, 2 8, 7, 6, 5 7, 3, 1, 6 1, 1, 1, 7The third number of the maximum-length snake sequence is?
- 第 6 題選擇
(5 points) For questions with sequences, we constantly split the problem into a number of sub-problems that are smaller instances of the same problem, and we try to solve the smaller problems recursively. We called this type of algorithm?
- 第 7 題選擇
(5 points) There is a large enough array with indices and which are initialized by 0, and functions and are defined as follows. Array and indices and can only be accessed in the functions and .
f(x): p ← p + 1 A[p] ← x g(): x ← A[p] p ← p - 1 return xWhich data structure is operated by those functions?
- 第 8 題選擇
(5 points) 承上題(陣列 與索引 初值皆 0,僅能由 存取)。If functions and are changed as following:
f(x): A[q] ← x q ← q + 1 g(): x ← A[p] p ← p + 1 return xWhich data structure is operated by those functions?
- 第 9 題選擇
(5 points) There is a binary tree stored in an array as:
in which is the parent of and , where is an index and means there is no element in the slot. What is its postorder traversal result?
- 第 10 題選擇
(5 points) 承上題(, 為 之父)。What is its BFS traversal result?
- 第 11 題選擇
(5 points) There are 10 hexadecimal data,
53, 3B, 66, 43, 60, 5B, 7C, 14, 30, 37, inserted in the given order into an empty hash table. The table is implemented using a circular array of 10 slots, and one slot can only have one item. The hash function for the table is . Which data is the first one that occurs a collision? - 第 12 題選擇
(5 points) 承上題(資料
53, 3B, 66, 43, 60, 5B, 7C, 14, 30, 37依序插入、10 槽環形陣列、)。If the hash table uses linear probing to resolve collisions and has no resizing mechanism, which position in the array is37inserted? - 第 13 題選擇
(5 points) There is a linked-list with elements . Let be the time complexity of inserting a new element to the tail of the list, and be that of deleting the last element . If there is only one pointer pointed to the head of the list, the functions are denoted . To improve it, we may also add another pointer pointed to the tail, so the functions become . Which of the following option is false if becomes large?
- 第 14 題選擇
(5 points) Given the following weighted graph, find its minimum spanning tree. Edges (undirected, weight):
F-B:1 H-C:2 B-C:3 I-H:4 F-I:5 B-A:6 A-E:7 E-C:8 D-E:9 F-D:10 D-B:11 D-A:12 A-C:13 E-H:14 G-E:15 D-G:16 F-G:17 I-G:18 G-H:19What is the sixth edge that Kruskal's algorithm includes (the numbering of the inclusion order starts from 1, not 0)?
- 第 15 題選擇
(5 points) 承上題的加權圖(邊如下):
F-B:1 H-C:2 B-C:3 I-H:4 F-I:5 B-A:6 A-E:7 E-C:8 D-E:9 F-D:10 D-B:11 D-A:12 A-C:13 E-H:14 G-E:15 D-G:16 F-G:17 I-G:18 G-H:19What is the sixth vertex that Prim's algorithm includes if starting from vertex A (the numbering of the inclusion order starts from 1, not 0)?
- 第 16 題選擇
(5 points) What is the value of the maximum flow for the following -flow network? Directed edges (capacity):
s→A:10 s→C:10 A→B:4 A→C:2 A→D:8 C→D:9 D→B:6 B→t:10 D→t:10 - 第 17 題選擇
(5 points) The Knuth-Morris-Pratt (KMP) algorithm is a string-matching algorithm. Its core is the prefix function. Given a pattern , the prefix function is . What is for the following pattern ?
1 2 3 4 5 6 7 8 9 10 a b a b a b a b c a - 第 18 題選擇
(5 points) Many string-matching algorithms build a finite automata. Below is a partially-completed state transition function for a string of length 10 over the alphabet (columns are states ; a blank means unspecified). It is possible to reconstruct from the partial table. How many A's does the string have?
0 1 2 3 4 5 6 7 8 9 A 4 5 2 B 0 0 7 3 C 0 0 0 10 - 第 19 題選擇
(5 points) What can you infer from the facts that ProblemA is NP-complete and ProblemA linear-time reduces to ProblemB?
- : If there exists an algorithm for ProblemB, then .
- : If there does not exist an algorithm for ProblemB, then .
- : If there exists an algorithm for ProblemB, then there exists an algorithm for ProblemA.
- : If there exists an algorithm for ProblemA, then there exists an algorithm for ProblemB.
- 第 20 題選擇
(5 points) The VERTEX-COVER problem is polynomial-time reducible to the SUBSET-SUM problem. Given an instance of VERTEX-COVER, one can construct a corresponding instance of SUBSET-SUM. The given graph has 5 edges ; with , is a vertex cover of size 3. The set is constructed (a modified base-4 encoding: one leading digit plus edge digits ):
e4 e3 e2 e1 e0 decimal x0 = 1 0 0 1 0 1 = 1041 x1 = 1 1 0 0 1 0 = 1284 x2 = 1 1 1 0 0 0 = 1344 x3 = 1 0 0 1 0 0 = 1040 x4 = 1 0 1 0 1 1 = 1093 y0 = 0 0 0 0 0 1 = 1 y1 = 0 0 0 0 1 0 = 4 y2 = 0 0 0 1 0 0 = 16 y3 = 0 0 1 0 0 0 = 64 y4 = 0 1 0 0 0 0 = 256What is the target ?