參考答案 / 中央 / 112 年 資料結構

國立中央大學資訊管理學系

中央 112 年資管所 資料結構 參考答案

共 10 題

參考答案 PDF各校參考答案的 PDF,訂閱考試資源分享信後會寄到您的信箱。訂閱領取 PDF

參考答案由作者與 AI 討論後逐題確認,不是各校公布的標準答案;若與各校公布不同,以各校為準。
最後更新:2026 年 11 月 3 日。發現錯誤歡迎來信。

這份考卷每一題的解析與手寫題的答題範例,收在《資管所考古題 111-115 計概資結全解》,可以免費試閱。

1(a)Build the MAX-Heap tree

考點:Heap 的建立與 heapify-up/heapify-down

初始陣列:[24, 58, 89, 36, 48, 77, 10, 94, 99]

bottom-up 建堆後最終陣列:[99, 94, 89, 58, 48, 77, 10, 24, 36]

1(b)Max-Heap 操作 best/worst/average 時間複雜度

考點:Binary Heap 與 Fibonacci Heap 操作複雜度比較表

Best O(1)、Worst O(logn);Average:Insert O(1)、Delete-Max O(logn)。

1(c)Heap Sort 執行一次後的 Max-Heap 樹

考點:Heap 的建立與 heapify-up/heapify-down

最終陣列:[94, 58, 89, 36, 48, 77, 10, 24],99 移至陣列尾端(已排序區)。

2Merge Sort 排序過程、複雜度與穩定性

考點:Merge Sort 與 Heap Sort 演算法邏輯、Stable 與 Unstable Sorting 分類整理

(a) [67, 88] [34] [98] [17] [26, 35] [4] [23] [30] → [34, 67, 88] [17, 98] [4, 26, 35] [23, 30] → [17, 34, 67, 88, 98] [4, 23, 26, 30, 35] → 4, 17, 23, 26, 30, 34, 35, 67, 88, 98

(b) Best、Average、Worst 皆為 Θ(nlogn)。

(c) 鍵值相等的資料排序後相對順序不變即為 stable;merge sort 是 stable。

3Fibonacci 數列(< 1000)遞迴/非遞迴虛擬碼

考點:遞迴(Recursion)基本概念:分而治之與 Base Case

(a)

function PrintFib(a, b):
    if a >= 1000: return
    print a
    PrintFib(b, a + b)

PrintFib(0, 1)

(b)

function PrintFibonacciIterative():
    a = 0
    b = 1
    print a
    while b < 1000:
        print b
        temp = a + b
        a = b
        b = temp

4Complete Graph 定義與邊數公式

考點:Simple Graph 與 Multiple Edges 定義

(a) 每一對相異頂點之間都恰有一條邊相連的 simple graph。

(b) x(x−1)2 條。

5BFS 與 DFS 演算法說明與範例

考點:BFS 與 DFS:定義、範例與比較

(a) BFS:以 Queue 逐層向外,先拜訪距起點 1 步的所有鄰居,再拜訪 2 步者。例:A→B→C→D→E→F。(如簡答圖)

(b) DFS:以 Stack 或遞迴沿一條路徑深入,無法前進才回溯。例:A→B→D→E→C→F。

5 參考答案圖

6MD5 處理大量資料的潛在弱點

考點:Hash Function 與雜湊表(Hash Table)基本概念

碰撞(collision):不同資料算出相同的 128-bit 摘要。輸出空間固定,資料量大時碰撞機率上升,且 MD5 已可實際構造碰撞,攻擊者能偽造摘要相同、內容不同的文件,破壞完整性驗證與數位簽章。

7Quick Sort 排序過程與 ANSI C 程式碼

考點:Quick Sort:DS版/Algo版 Partition 邏輯與 Worst-case 成因(Partition Three/Three-way Partition)

(a) pivot 取最後一個元素:pivot 86 → 75, 40, 61, 23, 54, 12, 86, 98;pivot 12 → 12, 40, 61, 23, 54, 75;pivot 75 不動;pivot 54 → 12, 40, 23, 54, 61;pivot 23 → 12, 23, 40;結果:12, 23, 40, 54, 61, 75, 86, 98。

(b)

#include <stdio.h>

void swap(int *a, int *b) {
    int t = *a; *a = *b; *b = t;
}

/* Lomuto partition:以最後一個元素為 pivot */
int partition(int arr[], int low, int high) {
    int pivot = arr[high];      /* 選最後一個元素當 pivot */
    int i = low - 1;            /* i:「<= pivot」區的右邊界 */
    int j;
    for (j = low; j < high; j++)
        if (arr[j] <= pivot) {
            i++;
            swap(&arr[i], &arr[j]);   /* 把小的換到左側 */
        }
    swap(&arr[i + 1], &arr[high]);    /* pivot 歸位 */
    return i + 1;                     /* 回傳 pivot 的最終 index */
}

void quickSort(int arr[], int low, int high) {
    if (low < high) {                 /* 區間 <= 1 個元素即終止 */
        int pi = partition(arr, low, high);
        quickSort(arr, low, pi - 1);  /* 遞迴左半 */
        quickSort(arr, pi + 1, high); /* 遞迴右半 */
    }
}

int main(void) {
    int arr[] = {75, 40, 61, 23, 54, 12, 98, 86};
    int n = sizeof(arr) / sizeof(arr[0]);
    int i;
    quickSort(arr, 0, n - 1);
    for (i = 0; i < n; i++)
        printf("%d ", arr[i]);
    return 0;
}

8Insertion Sort 與 Quick Sort 時間複雜度比較表

考點:初等排序:Bubble/Insertion/Selection Sort 演算法與範例

排序法 Best Average Worst
Insertion Sort O(n) O(n2) O(n2)
Quick Sort O(nlogn) O(nlogn) O(n2)

中央其他年份