資料結構與演算法
國立臺灣大學 2023 · 考試 · 16 題 · 限時 100 分
整卷連續作答,作答時答案與解析隱藏;按「交卷」後揭曉正解、標準解析並自動批改(申論/計算題不計分,供自行對照)。
- 第 1 題選擇
(5 points) Assuming we have data points. Among the variant characteristics of the data points, please select the correct descriptions.
- 第 2 題選擇
(5 points) B+ tree is an extension of B tree. The major differences from B tree are (1) all leaf nodes are linked together in a doubly-linked list, and (2) data points are stored on the leaf nodes only; internal nodes only hold keys and act as routers to the correct leaf node; the left child is smaller than the key and the right child is larger or equal than that. Please find any/all violations of a B+ tree structure in the following diagram. Assume the tree node can at most contain 4 data points (keys).
樹結構(由根往下;括號為標記候選):
- 根:
20- 左子(標記 (A)):
106,8→ 葉1,2,3/6,7/8,9- (標記 (B))
13,20→ 葉10,11/13,14/ (標記 (C))20,21
- 右子:
30,4022,27→ 葉 (標記 (D))22,23/24,25/27,2833,36→ 葉 (標記 (E))30,31/33,34/36,3747,52→ 葉40,43/47,49/52,55
- 左子(標記 (A)):
- 根:
- 第 3 題選擇
(5 points) Please find the following table for the characters and their corresponding occurring probabilities. Please design a Huffman encoding tree and select the correct descriptions.
Symbol () A B C D E F G Prob () 0.15 0.06 0.24 0.21 0.09 0.21 0.03 - 第 4 題選擇
(5 points)(單選)We now use several algorithms to traverse a binary tree. Assuming there are a total number of nodes, how many of the following statements about the worst-case space complexity are TRUE?
- Using DFS to traverse a balanced binary tree takes .
- Using DFS to traverse a binary tree takes .
- Using BFS to traverse a balanced binary tree takes .
- Using BFS to traverse a binary tree takes .
- 第 5 題選擇
(5 points)(單選)In a traditional merge sort, two sorted sub-arrays are combined to form a single, fully sorted array. This is referred to as a 2-way merge. The problem at hand is to extend this concept by merging sorted arrays of integers, where and are given integers representing the number of arrays and the number of integers in each array, respectively. Please choose the correct worst-case time complexity of this -way merge.
- 第 6 題選擇
(5 points) The following is a binary tree and the alphabet on the node is simply the "name" (instead of value) of the node. Please select the correct statements from the following:
樹結構(節點以名稱標示):
A:左子B、右子CB:左子D、右子EC:左子F、右子GD:右子HE:右子IF:左子JG:左子K、右子LL:右子M
- 第 7 題選擇
(5 points)(單選)Given a list of binary trees where each node is 0 or 1 shown as below, we would like to insert these trees into a linear-probing hash table of length . The hash function , where is the binary sequence obtained from in-order traversal of tree and converts a binary sequence to a decimal number. For instance, . Here's the question: how many collisions occur during the insertion process?
七棵樹皆為 7 節點完全二元樹(根;左子
cL、右子cR;cL的左右葉a,b;cR的左右葉c,d),中序序列為[a, cL, b, root, c, cR, d]:- :root=0, cL=0, cR=1, a=0,b=1,c=1,d=0
- :root=0, cL=0, cR=0, a=0,b=0,c=1,d=0
- :root=1, cL=0, cR=1, a=0,b=0,c=1,d=1
- :root=1, cL=0, cR=0, a=0,b=1,c=1,d=0
- :root=0, cL=0, cR=0, a=0,b=1,c=0,d=1
- :root=1, cL=0, cR=0, a=1,b=1,c=0,d=0
- :root=1, cL=1, cR=0, a=0,b=1,c=1,d=0
- 第 8 題選擇
(5 points) Postfix advantages: What is/are the advantage(s) of using postfix notation for math expressions?
- 第 9 題選擇
(5 points) DFS advantages: To find a feasible solution to the eight-queen problem, what is/are the reason(s) that we prefer to use DFS (depth-first search) instead of BFS (breadth-first search)?
- 第 10 題選擇
(5 points) Heap applications: Which one(s) of the following applications may involve the use of heaps to increase time efficiency?
- 第 11 題選擇
(5 points) Properties of dynamic programming (DP): Which of the following statements is/are correct about DP?
- 第 12 題選擇
(5 points) Properties of shortest path problem: Which of the following statements is/are correct?
- 第 13 題選擇
(5 points) Properties of min. spanning tree (MST): Let be a MST of a weighted graph with at least 3 vertices. Which of the following statements is/are correct?
- 第 14 題選擇
(5 points) Prefix, infix, and postfix: Which of the following statements is/are correct?
- 第 15 題申論
(21 points) Given singly linked lists, each of which has nodes. The numbers in the nodes of the -th list are given by . Each of the lists has the numbers sorted in non-decreasing order, i.e., . Professor Q asks the students to develop an algorithm to merge these lists into one singly linked list sorted in non-decreasing order. Three students have come up with different algorithms. For each of these three algorithms, analyze and give their asymptotic worst-case running times with big-O notation and in terms of and (tight bound; drop lower-order terms and constant factors other than and ).
- Student A: Repeatedly iterate over the numbers in the head nodes of the lists, find the node with the smallest number, remove from its original list and append it to the tail of result list ; until all lists are empty.
- Student B: Create an empty min heap . Remove the head nodes and insert them into (each node also carries the index of its source list). Repeatedly remove the min node from , append it to , and (if its source list is not empty) remove the head of list and insert into ; while is not empty.
- Student C: Recursive divide-and-conquer
MergeTwoGroupLists: if only one list, return it; otherwise split the input lists into two groups of and lists, recursively merge each group into one sorted list , then merge the two sorted lists into one.
- 第 16 題申論
(9 points) The pseudo code function to compute the prefix function in the Knuth-Morris-Pratt (KMP) string matching algorithm is given below. Given a pattern string , the prefix function is such that is the length of the longest prefix of that is a proper suffix of (the -character prefix of ). For pattern string
ABACABACABACABAD, how many times is line 7 executed?COMPUTE-PREFIX-FUNCTION(P) 1 m = P.length 2 let π[1..m] be a new array 3 π[1] = 0 4 k = 0 5 for q = 2 to m 6 while k > 0 and P[k+1] ≠ P[q] 7 k = π[k] 8 if P[k+1] == P[q] 9 k = k + 1 10 π[q] = k 11 return π