114 年 國立中央大學資訊工程學系碩士班《資料結構與演算法》
第 1 題
An empty 11-bucket hash table has hash function and adopts quadratic probing (i.e., , for ). Below is the resulting hash table after inserting 8 items.
| Index | Value |
|---|---|
| 0 | |
| 1 | |
| 2 | 25 |
| 3 | 59 |
| 4 | 37 |
| 5 | 27 |
| 6 | 16 |
| 7 | 17 |
| 8 | 15 |
| 9 | 38 |
| 10 |
Which of the following is/are the possible input sequence of these 8 items?
(A) 27 37 16 17 59 15 25 38
(B) 27 37 16 59 15 25 38 17
(C) 37 27 16 59 25 15 17 38
(D) 27 16 37 38 59 15 17 25
登入後即可作答並保存紀錄。
核心觀念
二次探測法在碰到已占用的位置時,依序檢查
直到找到空位。每個值的雜湊起始位置為 :
| 值 | 起始位置 |
|---|---|
| 27 | 5 |
| 37 | 4 |
| 16 | 5 |
| 17 | 6 |
| 59 | 4 |
| 15 | 4 |
| 25 | 3 |
| 38 | 5 |
解題方法
按照各選項的輸入順序,逐一找出每個值實際放入的位置。若四種順序都能得到題目所列的位置,四個選項便都是可行序列。以下位置序列依序對應各選項中的輸入值;每一步都放入探測順序中第一個空位。
選項分析
- (A) 正確。 輸入順序為 ,放入位置依序為 。例如 的起始位置 已占用,依序檢查 仍占用,再檢查 ,因此放在 。
- (B) 正確。 輸入順序為 ,放入位置依序為 。
第 2 題
Which of the following statements are correct?
(A) The postfix of is .
(B) The postfix of infix expression is
(C) The infix of the postfix expression is .
(D) The prefix of the postfix expression is .
登入後即可作答並保存紀錄。
核心觀念
中序式(infix)依運算子優先順序與結合律決定運算次序;後序式(postfix)把運算子放在運算元之後;前序式(prefix)則把運算子放在運算元之前。
將後序式轉成運算式時,可由左至右掃描:遇到運算元就推入堆疊,遇到二元運算子就取出兩個運算元組成子運算式,再將結果推回。組合時,先取出的項目是右運算元,後取出的項目是左運算元。
解題方法
逐項依運算子優先順序改寫,或用堆疊建立運算式樹,再比對題目所給的前序、後序或中序表示法。除法與乘法優先於加法、減法;同一優先順序的運算子由左至右結合。
選項分析
(A) 正確。
中序式為 。先計算括號內的加法與減法,再做除法,最後加上 ,因此後序式為
與選項相同。
(B) 錯誤。
中序式 中,除法與乘法優先於加法,且由左至右結合:
因此後序式應為
選項給的是 ,運算子順序不同,不能表示原式。
第 3 題
Given the input list is L = [28, 203, 16, 37, 127, 521, 63, 528, 210, 216, 941, 45].
Which of the following statements is (are) correct?
(A) At the end of second pass of LSD Radix sort, the 6-th element of the resulting
chain is 45.
(B) At the end of second pass of LSD Radix sort, the 8-th element of the resulting
chain is 528.
(C) At the end of second pass of LSD Radix sort, the 6-th element of the resulting
chain is 127.
(D) At the end of first pass of LSD Radix sort, the 8-th element of the resulting chain
is 216.
登入後即可作答並保存紀錄。
核心觀念
LSD Radix Sort(由低位數字優先的基數排序)從個位數開始,依序按十位數、百位數等進行排序。每一趟都必須使用穩定排序:同一數字桶中的元素,維持它們在上一趟中的先後順序。
解題方法
第一趟:依個位數穩定排序
將原序列依個位數分配到 至 的桶,再由小到大依序取出:
第一趟結果的第 個元素是 。
第二趟:依十位數穩定排序
以第一趟結果為輸入,依各數的十位數分桶。十位數相同時,保留第一趟中的原順序:
- 十位數為 :
- 十位數為 :
- 十位數為 :
- 十位數為 :
第 4 題
A binary tree has inorder traversal ILOVENCU, and postorder traversal ILVNCUEO. Which of the following statements is (are) true?
(A) The fifth letter in the level-order traversal is V
(B) The height of the binary tree is 4
(C) C is a leaf node
(D) The sixth letter in the level-order traversal is U
登入後即可作答並保存紀錄。
核心觀念
由二元樹的:
- Inorder(中序):左子樹 → 根 → 右子樹
- Postorder(後序):左子樹 → 右子樹 → 根
可利用後序走訪的最後一個節點找出根,再依中序走訪切分左右子樹。
本題採用「樹高=根節點到最深葉節點的邊數」定義。
解題方法
中序為:
後序為:
1. 找出根節點
後序最後一個字母是 ,因此 為根。
在中序中, 左側為 ,右側為 ,所以:
- 的左子樹包含
- 的右子樹包含
2. 建立左子樹
左子樹的中序為 ,後序為 。
後序最後一個為 ,所以 是根,且 為 的左子節點。
3. 建立右子樹
右子樹的中序為 ,後序為 。
後序最後一個為 ,所以 是右子樹根。
在中序中, 左側為 ,右側為 :
- 的左子節點為
- 的右子樹包含
對於 :
- 後序為 ,故根為
- 中序為 , 左側為
- 的後序為 ,故根為
- 的左子節點為
因此樹形如下:
第 5 題
Consider the code fragment below.
container.push('l');
container.push('L');
container.push('O');
container.push('V');
container.pop();
container.push('E');
container.pop();
container.push('N');
container.pop();
container.push('C');
container.push('U');
Which of the following statements is (are) true?
(A) If the "container" is an empty standard stack. The sequence of elements inside the
"container" from its top to the bottom is ILOCU
(B) If the "container" is an empty standard queue. The sequence of elements inside
the "container" from its front to its rear is VENCU
(C) If the "container" is an empty min heap, the level order traversal of the heap is
CNOVU
(D) If the "container" is an empty max heap, the level order traversal of the heap is
ULEIC
登入後即可作答並保存紀錄。
核心觀念
本題考查堆疊、佇列與二元堆積的操作規則:
- 堆疊採後進先出(LIFO),
pop()移除頂端元素。 - 佇列採先進先出(FIFO),
pop()移除 front 元素。 - 最小堆積每個父節點不大於子節點;最大堆積每個父節點不小於子節點。插入後向上調整,移除根節點後以末端元素補根,再向下調整。
- 依原圖,第一個字元是大寫
I。
解題方法
依序執行題目列出的操作。對堆積而言,pop() 視為移除根節點;每次插入或移除後,依堆積性質調整。
選項分析
(A) 錯誤。
堆疊依序 push I, L, O, V,pop 移除頂端的 V;再 push E 並 pop 移除 E;push N 並 pop 移除 N;最後 push C, U。
由底到頂為 I, L, O, C, U,所以由頂到底是 U, C, O, L, I,不是選項所說的 ILOCU。
(B) 正確。
佇列依序加入 I, L, O, V,前三次 pop() 分別移除 front 的 I, L, O。之後加入 E, N, C, U,剩餘元素由 front 到 rear 為 V, E, N, C, U,即 VENCU。
(C) 正確。
依最小堆積規則逐步操作:
第 6 題
Consider a red-black tree with level order 50, 30, 80, 90. Which of the following statements is (are) true?
(A) node 30 is red.
(B) After inserting 70 and 75, the level order traversal of the resulting red-black tree is
50, 30, 80, 70, 90, 75
(C) After inserting 70 and 75, node 90 in the resulting red-black tree is black.
(D) After inserting 70, 60, and 65, node 65 in the resulting red-black tree is black.
登入後即可作答並保存紀錄。
核心觀念
紅黑樹需符合以下性質:根節點為黑色;紅色節點的子節點必須是黑色;從任一節點到其所有後代空葉的每條路徑,黑色節點數相同。新節點插入時先著紅色,再依父節點、叔叔節點及相對位置進行重新著色或旋轉。
解題方法
初始層序為 ,因此 是根, 是 的左子節點, 是右子節點, 是 的右子節點。
由黑高度相同,經過 直接到空葉的路徑,與經過 到空葉的路徑必須有相同黑色節點數,因此 為紅色。如此一來, 必須為黑色,避免紅色父子相連;左側的 也必須為黑色,才能與右側路徑維持相同黑高度。
初始樹的顏色與結構為:
50黑
/ \
30黑 80黑
\
90紅
接著依序插入指定節點,逐步套用紅黑樹插入規則。
選項分析
(A) 錯誤。 由黑高度與紅黑樹性質可知, 必須是黑色,不是紅色。
第 7 題
Given a directed weighted graph G=(V, E), where each edge (i,j) ∈ E has weight w(i,j).
The adjacency matrix W is defined as below
Below is an algorithm for finding shortest paths of all vertex pairs in a directed weighted graph.
F (G,W)
{
n=|V|
D(0)=W
for (k = 1; k<= n; k=k+1)
for (i = 1; i<=n; i=i+1)
for (j = 1; j<= n; j=j+1)
if D(k-1)[i,j] > D(k-1)[i,k] + D(k-1)[k,j]
then D(k)[i,j] = D(k-1)[i,k] + D(k-1)[k,j]
else D(k)[i,j] = D(k-1)[i,j]
return D(n)
}
Which of the following statements are true?
(A) k is on the shortest path if
(B) if k is on the shortest path then
(C) if k is on the shortest path then
(D) k is on the shortest path if
登入後即可作答並保存紀錄。
這題考查 Floyd-Warshall 演算法,該演算法用於尋找圖中所有節點對之間的最短路徑。
演算法分析:
Floyd-Warshall 演算法使用動態規劃。 表示從節點 到節點 的最短路徑長度,其中路徑允許經過的節點編號最大為 。
演算法的遞迴關係是:
演算法的偽碼如下:
初始化 為鄰接矩陣 。
對於 從 1 到 (中間節點):
對於 從 1 到 (起始節點):
對於 從 1 到 (終點節點):
如果 ,則更新 。
否則,。
最終結果是 。
核心觀念:
在 Floyd-Warshall 演算法中,當 被更新為 時,意味著通過節點 的路徑比之前找到的任何不經過節點 (或只經過編號小於 的節點)的路徑更短。這表明節點 是構成從 到 的最短路徑的一部分(至少是目前為止的最短路徑)。
選項分析:
(A) k is on the shortest path if
這個選項說,如果 的值是通過 更新得到的,那麼 就在最短路徑上。
演算法的更新條件是 if D(k-1)[i,j] > D(k-1)[i,k] + D(k-1)[k,j],然後 D(k)[i,j] = D(k-1)[i,k] + D(k-1)[k,j]。
這表示,如果 的值是通過 更新的,那麼 就是從 到 經過節點 的最短路徑。因此, 就在這條最短路徑上。
這個敘述是正確的。
(B) if k is on the shortest path then
這個選項說,如果 在 到 的最短路徑上,那麼 就會被更新。
這並不總是正確的。 的值是 和 中的最小值。
第 8 題
Consider a UAV (Unmanned Aerial Vehicle) with F unit of fuel travels from NCU to a
destination "target" km away. There are n gas stations along the way. When the UAV
refuels at a gas station, all the fuel of the gas station is transferred into the UAV.
Suppose that the UAV consumes one unit of fuel for every kilometer it travels. Let the
position and fuel of a gas station indicate the distance between the gas station and NCU and
its volume of fuel, respectively. Return the minimum number of refueling stops the UAV
must make in order to reach its destination.
typedef struct {
int position;
int fuel;
} stop_info;
int Refuel(int target, int F, int n, stop_info s[]) {
int N_R = 0; // number of refuel
int i; //gas stations ID
stop_info X;
while (F <target) {
for (i=0; L1; ++i)
Q.push(s[i].fuel);
if (Q.empty()) return -1;
X=Q.pop();
F += X.fuel
N_R++;
}
return N_R;
}
What should be filled in blank L1?
(A) (i<n) && (s[i].position <=F)
(B) (i<n) && (s[i].fuel <=F)
(C) (i<n) && (s[i].position <=target)
(D) i<n
登入後即可作答並保存紀錄。
核心觀念
本題使用貪心法搭配最大堆。F 表示從 NCU 出發目前可到達的最遠距離;位置不超過 F 的加油站都已可抵達。每次從這些尚未處理的加油站中,選擇燃油量最大的站加油,讓可達距離增加最多。
解題方法
依原卷圖,position 是加油站距離 NCU 的公里數,fuel 是該站的燃油量;UAV 每公里消耗一單位燃油。加油站須依 position 由小到大排列,逐一將目前可抵達的站加入最大堆,再取出燃油量最大的站加油。
因此,內層條件要同時確認尚有加油站,且該站位置不超過目前可達距離:
為了避免每次進入 while 都從第一站重新掃描,i=0 應在 while 前設定,內層迴圈則保留目前索引。這樣每座加油站只會加入堆一次。
第 9 題
Consider Refuel algorithm above. Which of the following statements are true?
(A) Q could be a stack
(B) Q could be a priority queue
(C) Q could be a max heap
(D) Q could be min heap
登入後即可作答並保存紀錄。
這題考查 Refuel 演算法中優先佇列 Q 的選擇。演算法的目標是找到最少加油次數到達目的地。在每次需要加油時,演算法會從所有可到達的加油站中,選擇能提供最多燃料的加油站進行加油,以最大化行駛距離。
演算法邏輯回顧:
while (F < target) 迴圈表示當前燃料不足以到達目的地時,需要加油。
for 迴圈用於找到所有當前 UAV 可以到達的加油站(s[i].position <= F)。
Q.push(s[i].fuel) 將這些加油站提供的燃料量加入容器 Q。
X = Q.pop() 從容器 Q 中取出一個值。
F += X.fuel 更新 UAV 的總燃料量(或最大可到達距離)。
N_R++ 記錄一次加油。
Q 的作用:
演算法的目標是「最少加油次數」。為了達到這個目標,當 UAV 需要加油時,它應該選擇能讓它行駛最遠的那個加油站。這意味著,在所有可到達的加油站中,應該選擇提供最多燃料的那個。
因此,容器 Q 應該能夠高效地支援以下操作:
- 插入元素(燃料量)。
- 取出最大元素。
選項分析:
第 10 題
Consider Refuel algorithm above. Which of the following statements is true?
(A) The time complexity of Refuel algorithm above is
(B) The time complexity of the minimum number of refuel problem is
(C) The time complexity in Refuel algorithm above is
(D) The time complexity of the minimum number of refuel problem is
登入後即可作答並保存紀錄。
核心觀念
本題比較兩件事:
- 圖中
Refuel演算法本身的時間複雜度。 - 「最少加油次數」問題所能達到的最佳演算法複雜度。
演算法使用優先佇列 Q,每次從目前可到達的加油站中取出燃料量最大的站點,因此 push 與 pop 的成本為 。
解題方法
外層 while 每次加油後,內層 for 都從 重新掃描加油站:
每次 while 最多掃描 個加油站,因此掃描成本為:
此外,每次掃描可能將加油站加入優先佇列,單次 push 成本為 ,故整體優先佇列操作成本為:
因此,圖中 Refuel 演算法的複雜度為:
對於最少加油次數問題,可以按照加油站位置由近到遠掃描;當目前燃料不足以繼續前進時,從已經過的加油站中選擇燃料量最大的站點。每個加油站至多加入優先佇列一次、取出一次,所以:
選項分析
第 11 題
Which of the following statements about hashing algorithms are incorrect?
(A) A good hash function should distribute the keys uniformly into the slots of the table.
(B) The load factor of a hash table is the average number of keys per slot.
(C) Assume all keys are integers, and define . If has a divisor , a preponderance of keys that are congruent modulo can favorably affect uniformity.
(D) If open addressing is used for resolving collisions, the probe sequence should be a permutation of .
(E) Theoretically speaking, there is no perfect hashing.
登入後即可作答並保存紀錄。
核心觀念
本題考查雜湊(hashing)的基本性質:
-
雜湊函數均勻性:鍵值應盡量平均分布到雜湊表的各個槽位。
-
負載因子(load factor):
其中 為鍵的數量, 為槽位數量。
-
除法雜湊法:
-
開放定址法(open addressing):探測序列必須涵蓋所有槽位,才能在表中仍有空位時找到位置。
-
完美雜湊(perfect hashing):對固定的靜態鍵集合,能讓不同鍵映射到不同槽位,不發生碰撞。
解題方法
逐一檢查各選項是否符合上述定義。題目詢問的是「incorrect」,因此找出錯誤的敘述。
選項分析
(A) 正確
良好的雜湊函數應將鍵值均勻分布到雜湊表的各個槽位,避免某些槽位集中大量鍵值而造成碰撞。
因此此敘述正確。
(B) 正確
若雜湊表有 個鍵、 個槽位,負載因子為:
這正是每個槽位平均承擔的鍵數,因此此敘述正確。
(C) 錯誤
第 12 題
The Longest Common Subsequence (LCS) problem finds a longest subsequence
common to two given sequences x[1..m] and y[1..n]. Which of the following
statements are incorrect?
(A) If we simply check every subsequence of x[1.. m] to see if it is also a subsequence
of y[1..n], the worst-case running time is .
(B) If we define , where denotes the length of
the string, then .
(C) if ; Otherwise,
.
(D) The recursive formulation of LCS indicates that the complexity of its dynamic
algorithm is potentially exponential.
(E) If , then any prefix of is an LCS of a prefix of and a prefix of .
登入後即可作答並保存紀錄。
核心觀念
本題考最長共同子序列(LCS)的暴力枚舉複雜度、動態規劃狀態定義與遞迴式,以及 LCS 的最優子結構。
令 表示 與 的 LCS 長度。標準遞迴式為:
搭配邊界條件 ,填滿 個狀態即可得到答案,時間複雜度為 。
解題方法
依原卷第 5 頁第 12 題,題目給定 與 ,詢問哪些敘述錯誤。圖中 (A) 的複雜度是 ;(C) 在字元不同時,將兩個子問題的結果寫成相加。
逐項核對:暴力法最多枚舉 的 個子序列,每個候選子序列可掃描 檢查,需 時間,因此 (A) 符合 。再以標準 LCS 遞迴式核對 (C),即可判斷其錯誤;(D) 則要區分未記憶化的遞迴法與動態規劃。
選項分析
- (A) 正確。 長度為 的序列共有 個子序列(包含空序列)。逐一檢查每個候選子序列是否也是 的子序列,每次掃描 的時間為 ,總時間為 。
- **(B) 正確。
第 13 題
Which of the following statements about Minimum Spanning Tree are incorrect?
(A) The spanning tree of a graph exists uniquely which connects all vertices with the
minimum total edge weight.
(B) Both Prim's and Kruskal's algorithms are greedy algorithms.
(C) After optimization, Prim's and Kruskal's algorithms have the same (worst case)
time complexity.
(D) Disjoint-set data structure can be used to improve the time complexity of the
Prim's algorithm.
(E) Fibonacci heap can be used to improve the time complexity of the Kruskal's
algorithm.
登入後即可作答並保存紀錄。
核心觀念
生成樹是連通圖中連接所有頂點、且沒有環的子圖,因此含有 條邊。最小生成樹(MST)則是總邊權重最小的生成樹;權重相同時,最小生成樹不一定唯一。
Prim 與 Kruskal 都依據「安全邊」逐步構造最小生成樹:Prim 擴張目前的樹,Kruskal 依邊權重由小到大加入不會形成環的邊。兩者都是貪婪演算法,但常用的資料結構與時間複雜度不同。
解題方法
原卷第 5 頁第 13 題列出 A–E 五個關於最小生成樹的敘述,沒有附加權圖或其他數據。判斷時,先檢查唯一性是否必然成立,再確認 Prim、Kruskal 各自搭配的資料結構與標準時間複雜度。
選項分析
(A) 錯誤。 最小生成樹不一定唯一。例如三角形的三條邊權重全為 ,任選兩條邊都能形成最小生成樹,因此共有三種。所有邊權重互異可以保證唯一,但題目沒有這項條件。
(B) 正確。 Prim 每次選取連接目前樹與外部頂點的最小權重邊;Kruskal 每次選取尚未造成環的最小權重邊。兩者都是逐步選取安全邊的貪婪演算法。
(C) 錯誤。 Prim 使用 Fibonacci heap 時,時間複雜度可達
第 14 題
Which of the following statements about the Maximum Flow problem are incorrect?
(A) In a flow network, source node has no incoming flow and terminal (sink) node has
no outgoing flow.
(B) Each edge has forward flow and backflow, and the two flows must always be inverses
of each other.
(C) Ford-Fulkerson algorithm finds the maximum flow from source to terminal with
time complexity , where E represents the number of edges and f is the
maximum flow of the final graph.
(D) If we look at all the possible cuts in the graph, and find the largest capacity of those
cuts, then that value is the value of the maximum flow for that network.
(E) If a network has antiparallel edges (i.e., the edges connecting two nodes back and
forth), we can convert it to an equivalent one with no antiparallel edges.
登入後即可作答並保存紀錄。
核心觀念
本題考最大流的端點與流量定義、反對稱流量、Ford–Fulkerson 演算法複雜度、最大流最小割定理,以及如何處理反向平行邊。
以 表示頂點 到 的帶符號淨流量時,反對稱性為
除源點 與匯點 外,各頂點須滿足流量守恆。對任一 - 割 ,流量值不會超過割容量;最大流最小割定理進一步指出,最大流值等於最小割容量。
解題方法
依附圖第 5 頁可讀出第 14 題詢問哪些最大流敘述錯誤,並列有 (A)–(E) 五項;圖中沒有特定網路或容量數值,因此依流量定義、最大流最小割定理與 Ford–Fulkerson 的複雜度逐項判斷。
判斷關鍵是分清「最大流」與「最小割」的關係:對每一個割,最大流值都不大於其容量,且最大流值等於所有割中容量最小者。因此,聲稱要找容量最大的割,便與定理不符。
選項分析
- (A) 正確。 最大流的端點慣例是流由源點淨流出、流入匯點;取最大流時,可令流入源點與流出匯點的流量為 。因此此敘述符合標準設定。
第 15 題
Which of the following statements about Single-Source Shortest Paths problem are incorrect?
(A) If a graph contains a negative-weight cycle, then all shortest paths do not exist.
(B) A subpath of a shortest path is a shortest path.
(C) Dijkstra’s algorithm finds single-source shortest paths in graphs with nonnegative-weight cycles.
(D) If binary heap is used, the worst-case time complexity of Dijkstra’s algorithm is , where represents the number of edges and the number of vertices.
(E) If the weight of all edges is the same, there is a faster algorithm than Dijkstra’s algorithm to compute single-source shortest paths.
登入後即可作答並保存紀錄。
核心觀念
單源最短路徑的幾個基本事實:
- 負權重環只會影響「從起點可到達該環、且從環可到達」的頂點。
- 最短路徑具有最佳子結構。
- Dijkstra 演算法要求所有邊權非負。
- Dijkstra 的複雜度取決於優先佇列:binary heap 為 ,Fibonacci heap 為 。
- 邊權全相同時,最短路徑就是最少邊數路徑,可用 BFS。
題目問的是哪些敘述錯誤。
解題方法
逐項檢查敘述是否過度絕對、條件是否放錯,或把複雜度配錯資料結構。
選項分析
(A) 圖中有負權重環,則所有最短路徑都不存在:錯誤。 只有從起點能到達該負環、且從該環能再到達的頂點,其最短路徑才不存在(繞環可無限降低權重)。與負環無關的頂點,最短路徑仍然存在。「所有」說得太絕對。
(B) 最短路徑的子路徑也是最短路徑:正確。 這是最佳子結構。若子路徑 不是最短,用更短的路徑替換後可得更短的整條路徑,與原路徑為最短矛盾。
(C) Dijkstra 可在「nonnegative-weight cycles」的圖上求單源最短路徑:錯誤。 Dijkstra 的條件是邊權皆非負,而不是環權非負。
第 16 題
Choose necessary step(s) to prove that a decision problem is NP-complete:
(A) Show that the problem can polynomially reduce to an NP-complete problem.
(B) Design a non-deterministic algorithm to solve the problem in exponential time complexity.
(C) Design a non-deterministic algorithm to solve the problem in polynomial time complexity.
(D) Design a deterministic algorithm to solve the problem in polynomial time complexity.
(E) Show that an NP-hard problem can polynomially reduce to the problem .
登入後即可作答並保存紀錄。
核心觀念
要證明決策問題 是 NP-complete(NP 完全),必須同時證明兩件事:
- :給定一個「是」實例及其證明憑證,可以在多項式時間內驗證;等價地,可以用非決定性多項式時間演算法解決 。
- 是 NP-hard(NP 困難):對某個已知的 NP-hard 問題 ,證明 ,也就是 可在多項式時間內歸約到 。
歸約方向必須是「已知困難問題 」。這表示若能有效解決 ,也能藉由歸約有效解決 ,因此 至少和 一樣難。
解題方法
把 NP 完全的定義拆成兩個必要部分:先確認選項中哪個能證明 ,再確認哪個能證明 為 NP-hard。兩部分都成立,才能得出 為 NP-complete。
選項分析
(A) 錯誤。
此選項要求證明 ,其中 是 NP-complete 問題。這個方向至多表示 可歸約到一個 NP 問題,不能據此證明 是 NP-hard。要證明 困難,歸約方向應為已知 NP-hard 問題 。
第 17 題
Choose correct statement(s):
(A) If a problem can polynomially reduce to an NP-hard problem, then is NP-hard.
(B) If we can prove that an existing NP-complete problem can polynomially reduce to a problem , then is NP-hard.
(C) An NP-hard problem can polynomially reduce to any NP-hard problem.
(D) All NP problems can polynomially reduce to any NP-complete problem.
(E) All NP problems can polynomially reduce to any NP-hard problem.
登入後即可作答並保存紀錄。
核心觀念
本題考的是多項式時間歸約的方向,以及 NP-hard 與 NP-complete 的定義。
若決策問題 可多項式時間歸約至問題 ,記為 ,表示可在多項式時間內把 的輸入轉換成 的輸入,並保留答案。多項式時間歸約具有傳遞性:
問題 是 NP-hard,若每個 NP 問題 都滿足 。問題 是 NP-complete,則須同時滿足 與 為 NP-hard。
解題方法
逐項檢查歸約箭頭的方向。證明問題 是 NP-hard,常用方法是從已知的 NP-complete 問題 歸約到 ,也就是證明 。因為任意 NP 問題 都可歸約到 ,再由傳遞性可得:
這正符合 為 NP-hard 的定義。反向的 則不能據此推出 是 NP-hard。
選項分析
第 18 題
Choose correct statement(s):
(A) If , then we can say .
(B) If , then we can say .
(C) If , then we can say .
(D) If , then we can say .
(E) If , then we can say .
登入後即可作答並保存紀錄。
核心觀念
本題考查漸近符號的定義,以及如何從多項式的最高次項判斷成長率。
若存在常數 與 ,使得對所有 都有 ,則 。若對所有 都有 ,則 。
對多項式而言,最高次項決定漸近成長率。本題的函數為
將它除以 :
因此,當 充分大時, 與 同階,也就是 。
解題方法
先找出最高次項,判斷 的基本成長率為 。接著利用漸近界的傳遞關係:
- ,所以 。
- ,所以 。
- 多項式 的成長速度低於指數函數 ,所以 。
- 同時代表 與 。
選項分析
第 19 題
Choose correct statement(s):
(A) Dynamic programming is used to solve problems that can be broken down into overlapping subproblems.
(B) The Longest Common Subsequence (LCS) problem can be solved by dynamic programming with a time complexity of , where and are the lengths of the two sequences.
(C) Dynamic programming always uses a 2D table for storing intermediate results.
(D) In dynamic programming, memoization stores solutions to subproblems to avoid redundant computations.
(E) Dynamic programming can only be applied to problems with a greedy choice property.
登入後即可作答並保存紀錄。
核心觀念
本題考動態規劃的適用特性、LCS 的時間複雜度,以及備忘錄法與貪婪選擇性質的差異。動態規劃常用於具有重疊子問題與最佳子結構的問題;備忘錄法則將已解出的子問題結果保存起來,避免重複計算。
解題方法
依原卷第 19 題,題目列出五個敘述:動態規劃與重疊子問題的關係、LCS 的時間複雜度、是否必定使用二維表、備忘錄法的用途,以及動態規劃是否需要貪婪選擇性質。逐項比對動態規劃的定義與 LCS 的標準演算法即可判斷。
選項分析
(A) 正確。 動態規劃常用來處理可拆解成重疊子問題的問題。由於不同計算路徑可能需要解相同子問題,保存結果可以避免重複計算。重疊子問題是重要特性,但完整判斷通常也要考慮問題是否具有最佳子結構。
(B) 錯誤。 設兩個序列長度分別為 與 ,標準 LCS 動態規劃會填寫約 個狀態,每個狀態花費常數時間,因此時間複雜度為
第 20 題
Choose correct statement(s):
(A) Breadth-First Search (BFS) and Depth-First Search (DFS) are non-uninformed search strategies.
(B) A* algorithm combines the actual cost from the start node () and the heuristic estimate to the goal (). If the heuristic is admissible (never overestimates the true cost) and consistent (satisfies the triangle inequality), A* always guarantees finding the optimal solution.
(C) Hill Climbing can escape from a local optimum due to its greedy nature.
(D) Branch and Bound uses both upper and lower bounds to prune the search space for saving computation.
(E) Dijkstra’s algorithm guarantees the shortest path even if the graph contains cycles.
登入後即可作答並保存紀錄。
核心觀念
本題考搜尋策略、A* 最佳性、爬山法的局部最佳問題、分枝限界法的剪枝,以及 Dijkstra 演算法對圖形條件的要求。
解題方法
依原卷圖,第 20 題的 (A) 寫的是「BFS 與 DFS 是 non-uninformed search strategies」;(B) 提到 A* 使用 與 ,並要求啟發式函數可採納且一致;(E) 問的是圖中有循環時 Dijkstra 是否仍保證最短路徑。逐項對照這些演算法的定義與適用條件即可判斷。
選項分析
-
(A) 錯。 BFS 與 DFS 都是非資訊式搜尋(uninformed search)策略,不使用到目標的啟發式估計。題目寫「non-uninformed」,意指「不是非資訊式搜尋」,因此敘述錯誤。
-
(B) 對。 A* 的評估函數為
其中 是從起點到節點 的實際成本, 是從 到目標的估計成本。