112 年 國立成功大學工程科學系碩士班乙組《資料結構》

📄 試題原卷 免費註冊後即可對照原始考卷 PDF免費註冊

第 1 題20 分

  1. Please answer the questions by the following tree. (20%)
    🖼️【此處有附圖,請對照原卷】
    (a) In-order traversal.
    (b) Pre-order traversal.
    (c) Post-order traversal.
🖼️ 本題含圖表,以下為原卷對應頁面:
原卷第 2 頁

登入後即可作答並保存紀錄。

這一題的完整詳解

核心觀念

本題考二元樹的三種深度優先走訪方式:

  • 中序走訪:左子樹 → 根節點 → 右子樹。
  • 前序走訪:根節點 → 左子樹 → 右子樹。
  • 後序走訪:左子樹 → 右子樹 → 根節點。

依原圖,根節點為 1;1 的左、右子節點分別為 7、9;7 的子節點為 3、4,3 的子節點為 2、5;9 的子節點為 6、8。

解題方法

依各種走訪的固定順序,從根節點開始,分別走訪左、右子樹。每個子樹也套用相同規則:

🔒

後續完整解題步驟與【答案】

免費註冊,享三天全站完整詳解閱覽。

免費註冊

第 2 題20 分

  1. Consider following a directed graph with weight and answering the questions. (20%)
    🖼️【此處有附圖,請對照原卷】
    (a) m = 18, b = 11, a = 5 find the shortest path and minimum cost from A to J.
    (b) m = 34, b = 33, a = 31 find the shortest path and minimum cost from E to C.
    (c) m = 8, b = 6, a = 8 find the shortest path and minimum cost from C to G.
    (d) m = 25, b = 48, a = 73 find the shortest path and minimum cost from G to C.
🖼️ 本題含圖表,以下為原卷對應頁面:
原卷第 2 頁

登入後即可作答並保存紀錄。

這一題的完整詳解

核心觀念

本題考有向加權圖的最短路徑。路徑只能沿箭頭方向前進,路徑成本是沿途邊權重的總和。各邊權重皆非負,因此可用戴克斯特拉演算法:每次選取目前暫定距離最小的頂點,確定其距離,再用 d(v)←min⁡{d(v),d(u)+w(u,v)}d(v)\leftarrow\min\{d(v),d(u)+w(u,v)\} 更新相鄰頂點。

解題方法

依原圖,GG 在右上、CC 在左下;重要方向與權重如下,參數 mm、bb、aa 分別標在 A→HA\to H、E→IE\to I、F→EF\to E:

A→H(m),A→B(21),H→G(46),H→I(30),I→A(21),I→B(18),I→C(41),I→J(41),B→C(18),C→D(30),D→I(33),G→F(41),F→J(33),F→E(a),J→G(33),J→E(36),E→I(b),E→D(30).\begin{aligned} &A\to H(m),\quad A\to B(21),\\ &H\to G(46),\quad H\to I(30),\\ &I\to A(21),\quad I\to B(18),\quad I\to C(41),\quad I\to J(41),\\ &B\to C(18),\quad C\to D(30),\quad D\to I(33),\\ &G\to F(41),\quad F\to J(33),\quad F\to E(a),\\ &J\to G(33),\quad J\to E(36),\quad E\to I(b),\quad E\to D(30). \end{aligned}

以下「確定距離順序」列出戴克斯特拉演算法依序確定的頂點與距離;其他候選距離若大於已知標籤,就不會取代它。

(a) m=18, b=11, a=5m=18,\ b=11,\ a=5,由 AA 到 JJ

從 AA 出發,先得到 d(H)=18d(H)=18、d(B)=21d(B)=21。接著 HH 更新出 d(I)=48d(I)=48、d(G)=64d(G)=64;BB 經 CC 得 d(C)=39d(C)=39;II 更新出 d(J)=89d(J)=89;CC 再得到 d(D)=69d(D)=69。

確定距離順序為:

A:0, H:18, B:21, C:39, I:48, G:64, D:69, J:89, F:105, E:110A:0,\ H:18,\ B:21,\ C:39,\ I:48,\ G:64,\ D:69,\ J:89,\ F:105,\ E:110

JJ 的最短距離由 I→JI\to J 得到,因此最短路徑為 A→H→I→JA\to H\to I\to J,成本為 18+30+41=8918+30+41=89。例如,經 G,FG,F 到 JJ 的成本為 18+46+41+33=13818+46+41+33=138,較大。

(b) m=34, b=33, a=31m=34,\ b=33,\ a=31,由 EE 到 CC

從 EE 出發,d(D)=30d(D)=30、d(I)=33d(I)=33。先確定 DD 時,經 D→ID\to I 得到的候選距離為 6363,不優於 II 的 3333。確定 II 後,d(B)=51d(B)=51、d(C)=74d(C)=74、d(A)=54d(A)=54、d(J)=74d(J)=74;再由 B→CB\to C 將 d(C)d(C) 更新為 51+18=6951+18=69。

確定距離順序為:

🔒

後續完整解題步驟與【答案】

免費註冊,享三天全站完整詳解閱覽。

免費註冊

第 3 題20 分

  1. Assume a polynomial has K non-zero element, we will represent a 1-D array A[1...2K+1] as following hint.
    Please answer the following questions. (20%)
    [hint]
    1
    2
    3
    4
    5
    K
    coefficient
    exponent
    2K+1
    (a) A polynomial is store in the above way, giving an array poly=[5,15,25,35,14,7,3,5,12,178,0], please
    translate the polynomial into P(x).
    (b) P(x)=7x+9x+6, please use an array to represent P(x) in the above way.
🖼️ 本題含圖表,以下為原卷對應頁面:
原卷第 3 頁

登入後即可作答並保存紀錄。

這一題的完整詳解

解題方法

由原卷提示可讀出:陣列第 1 格存非零項數 KK;之後每兩格依序存一組「係數、指數」。第 (b) 小題的原卷式子為 P(x)=7x5+9x3+6P(x)=7x^5+9x^3+6。

核心觀念

若多項式有 KK 個非零項,表示法為

[A1, A2, A3, …, A2K, A2K+1][A_1,\ A_2,\ A_3,\ \ldots,\ A_{2K},\ A_{2K+1}]

其中 A1=KA_1=K,而第 ii 項由係數與指數組成一對,依序寫入陣列。指數為 00 的項代表常數項。

逐題推導

(a) 給定陣列共有 1111 個元素,因此 K=(11−1)/2=5K=(11-1)/2=5。從第 2 格起依序配對:

(A2,A3)=(15,25),(A4,A5)=(35,14),(A6,A7)=(7,3),(A8,A9)=(5,12),(A10,A11)=(178,0)(A_2,A_3)=(15,25),\quad (A_4,A_5)=(35,14),\quad (A_6,A_7)=(7,3),\quad (A_8,A_9)=(5,12),\quad (A_{10},A_{11})=(178,0)

每一對分別表示一項係數與指數,因此

🔒

後續完整解題步驟與【答案】

免費註冊,享三天全站完整詳解閱覽。

免費註冊

第 4 題20 分

  1. Please change the follow two infix functions to prefix and postfix. (20%)
    (a) A+B-C+D-E-F
    (b) G/(H+I-J)K+L(M-N)

登入後即可作答並保存紀錄。

這一題的完整詳解

(a)
前綴:- - + - + A B C D E F
後綴:A B + C - D + E - F -

(b)
前綴:+ * / G - + H I J K * L - M N

🔒

後續完整解題步驟與【答案】

免費註冊,享三天全站完整詳解閱覽。

免費註冊

第 5 題20 分

  1. Answer "True" or "False" to the following statements. (20%)
    (1). If we sort time complexity by execution time, O(n²)<O(nlogn).
    (2). The Big-O of the polynomial 8n+5n+51 is O(n²).
    (3). If the polynomial f(x)=16x+8x+63x+85x stored by coefficients, you need an array of length 7.
    (4). The linked-list allows random access, but arrays only allow sequence access.
    (5). When the type and number of elements are the same, the memory space used by linked-list will be more than array.
    (6). When doing quicksort, assume that we can split the array in half with every pivot we choose, we can reach the best case of time complexity, which is O(nlgn).
    (7). When doing quicksort, assume that we choose the first element of the subarray as pivot in every round, we will reach the worst case of time complexity whether the array was originally in ascending or descending order.
    (8). A stable sorting means that the time complexity of the algorithm stays the same in best case, worst case and average case,eg.heap sort, merge sort.
    (9). When doing insertion sort, if we insert the smallest element to the front and the largest element to the end in one round, the time complexity will be better(n^3/2).
    (10). The space complexity if heap sort is O(1).

登入後即可作答並保存紀錄。

這一題的完整詳解

核心觀念

本題涵蓋《資料結構》與《演算法分析》四大核心主題:

  1. 時間與空間複雜度分析(Asymptotic Notation & Complexity):漸進符號之成長階次(Order of Growth)、多項式 Big-OO 漸進上界表示法、空間複雜度計算。
  2. 基本資料結構特性(Data Structures & Memory Allocation):多項式之順序陣列表示法(Array Representation of Polynomials)、陣列與鏈結串列(Array vs. Linked List)在存取模式(Random Access vs. Sequential Access)與記憶體空間開銷(Memory Overhead)之比較。
  3. 排序演算法機制與性質(Sorting Algorithms & Properties):
    • 快速排序法(Quicksort):最佳與最差情況之遞迴關係式與分割分析。
    • 穩定排序(Stable Sort)之精確定義與典型排序演算法(Heap Sort, Merge Sort)之穩定性與時間複雜度比較。
    • 插入排序法(Insertion Sort)及其變體之漸進時間複雜度界限。
    • 堆積排序法(Heap Sort)之原位排序(In-place Sorting)空間複雜度特性。

解題方法

本題為 10 題是非題,解題切入點如下:

  1. 依據時間複雜度定義,比較漸進階次 O(1)<O(log⁡n)<O(n)<O(nlog⁡n)<O(n2)<O(n3)<O(2n)O(1) < O(\log n) < O(n) < O(n \log n) < O(n^2) < O(n^3) < O(2^n),釐清執行時間隨資料量 nn 成長之快慢關係。
  2. 多項式若採用「按指數儲存係數」之順序陣列(Dense Array Representation),陣列長度需由最高次數(Degree dd)決定,長度為 d+1d + 1。
  3. 比較連續記憶體(Array,支援 O(1)O(1) 隨機存取)與指標連結(Linked List,僅支援 O(n)O(n) 順序存取且需額外指標空間)之結構差異。
  4. 針對 Quicksort,檢驗 Pivot 選擇對分割品質與遞迴關係式(Recurrence Relation)之影響;對雙向優化 Insertion Sort 進行搬移次數之最差情況界限估算。
  5. 嚴格區分「穩定排序(Stable Sort)」與「時間複雜度在不同 Case 下保持恆定」之概念差異。

選項分析

(1) False

  • 題目原文:If we sort time complexity by execution time, O(n²)<O(nlogn).
  • 詳解:當輸入規模 n→∞n \to \infty 時,時間複雜度之漸進階次關係為 O(nlog⁡n)<O(n2)O(n \log n) < O(n^2)。階次越小代表演算法的執行時間成長越慢、執行效率越高。因此,就執行時間而言,O(nlog⁡n)O(n \log n) 的執行時間少於 O(n2)O(n^2),敘述寫成 O(n2)<O(nlog⁡n)O(n^2) < O(n \log n) 為錯誤。

(2) False

  • 題目原文:The Big-O of the polynomial 8n+5n+51 is O(n²).
  • 詳解:多項式 f(n)=8n+5n+51=13n+51f(n) = 8n + 5n + 51 = 13n + 51,其最高次項為 n1n^1。在演算法複雜度分析中,漸進緊密上界(Tight Upper Bound)應表示為 O(n)O(n)。雖然數學定義上 13n+51∈O(n2)13n + 51 \in O(n^2),但在資料結構與演算法之標準規範中,多項式之 Big-OO 階次必由其最高次方決定,故該敘述將其標註為 O(n2)O(n^2) 屬錯誤表示。

(3) True

  • 題目原文:If the polynomial f(x)=16x+8x+63x+85x stored by coefficients, you need an array of length 7.
  • 詳解:原題多項式最高次方項為 x6x^6(即 f(x)=16x6+8x4+63x2+85x0f(x) = 16x^6 + 8x^4 + 63x^2 + 85x^0)。若採用係數陣列表示法(Dense Coefficient Array),必須為指數 00 到最高次數 dd 的每一個次方分配一個陣列元素位置。當最高次數 d=6d = 6 時,需要的陣列長度為 d+1=6+1=7d + 1 = 6 + 1 = 7(對應索引 0,1,2,3,4,5,60, 1, 2, 3, 4, 5, 6)。故敘述正確。

(4) False

  • 題目原文:The linked-list allows random access, but arrays only allow sequence access.
  • 詳解:陣列(Array)佔用連續記憶體空間,可透過基底位址與索引直接計算記憶體位址,支援 O(1)O(1) 時間的隨機存取(Random Access);而鏈結串列(Linked List)的節點散佈於記憶體中,必須自頭節點(Head)順著指標逐一走訪,僅支援 O(n)O(n) 時間的順序存取(Sequential Access)。題目將兩者的存取特性顛倒敘述,故為錯誤。

(5) True

  • 題目原文:When the type and number of elements are the same, the memory space used by linked-list will be more than array.
  • 詳解:若儲存相同的資料型別與元素個數,陣列僅需儲存資料本身;鏈結串列的每個節點除了儲存資料欄位(Data Field)之外,還必須額外配置指標欄位(Pointer Field,如 next 或 prev)以維護節點間的連結關係。因此鏈結串列的記憶體空間開銷必定大於陣列。故敘述正確。
🔒

後續完整解題步驟與【答案】

免費註冊,享三天全站完整詳解閱覽。

免費註冊

其他考古題