108 年 國立政治大學數位內容碩士學位學程資訊技術組《計算機概論與程式設計》
第 1 題45 分
- Single-choice (45%)
(1) Which of the following statements is wrong?
(a) A failure of a component may not lead to system failure
(b) MTTR means mean time to repair
(c) To improve availability, we either reduce MTTF or increase MTTR
(d) To improve MTTF, we can perform fault avoidance, fault tolerance, or fault forecasting.
(2) Which of the following statement is true?
(a) Pipelining improves instruction throughput and reduces the time it takes to complete an individual instruction
(b) A multi-cycle implementation of the MIPS processor requires that a single memory be used for both instructions and data
(c) Increasing the depth of pipeline increases the impact of hazards
(d) Forwarding is a method to resolve a control hazard.
(3) Which of the following statement is true?
(a) JPEG is a lossless data compression format
(b) MP3 is a lossless data compression format
(c) Pixel is the smallest unit in an digital image
(d) DPI refers to a display's resolution
(4) Which of the following interface/protocol does not transmit digital data?
(a) HDMI
(b) Bluetooth
(c) D-Sub
(d) DVI
(5) Which of the following statement is true?
(a) UML is a visual tool to generate executable code
(b) UML is a visual tool to generate code template
(c) UML is a visual programming language
(d) UML is a software development process
(6) Which of the following statements is wrong?
(a) DRAM write can wear out memory bits
(b) SRAM is low density, high power, expensive, but fast
(c) Data stored in DRAM as a charge in a capacitor so that it must periodically be refreshed
(d) DRAM addresses in 2 halves
登入後即可作答並保存紀錄。
第 1 大題:單選題詳解(共 6 小題)
(1) Which of the following statements is wrong?
-
核心觀念:
計算機系統的可靠度(Reliability)與可用度(Availability)度量指標。- MTTF(Mean Time To Failure,平均無故障時間):系統或組件從正常運作到發生故障的平均時間。
- MTTR(Mean Time To Repair,平均修復時間):發生故障後至修復完成回到正常運作的平均時間。
- MTBF(Mean Time Between Failures,平均故障間隔時間):。
- 可用度(Availability):系統處於可用運作狀態的時間比例,定義公式為:
-
選項分析:
- (a) 正確:單一元件損壞(Component failure)若系統具有容錯(Fault tolerance)或冗餘備援(Redundancy,例如 RAID、雙電源供應),不一定會導致整個系統癱瘓(System failure)。
- (b) 正確:MTTR 即代表 Mean Time To Repair(平均修復時間)。
- (c) 錯誤:由可用度公式可知,欲提高可用度(Availability),必須增加 MTTF(拉長正常運作時間)或減少 MTTR(縮短維修時間)。選項敘述「reduce MTTF or increase MTTR」與正確方向完全相反。
- (d) 正確:根據可靠度工程定義,提升 MTTF 的三大關鍵手段包含:故障避免(Fault avoidance)、容錯設計(Fault tolerance)以及故障預測(Fault forecasting)。
-
解題技巧:
可用度即「可用時間佔總時間的比例」。想讓系統常常可用,直觀上必須「故障修得快(MTTR 越小越好)」且「撐得久不壞(MTTF 越大越好)」。 -
【答案】:(c)
(2) Which of the following statement is true?
-
核心觀念:
計算機組織中的管線化(Pipelining)架構特性、效能衡量指標與冒險(Hazards)處理。- 管線化利用指令重疊執行來提升指令吞吐量(Instruction Throughput),但對單一指令的執行延遲(Latency / Execution time)並不會減少,甚至可能因為管線暫存器延遲而略微增加。
- 管線深度(Pipeline Depth)增加,代表管線級數變多,分支預測錯誤的懲罰(Branch penalty)與資料相依(Data dependency)造成的暫停週期(Stall cycles)影響隨之放大。
- 前瞻傳遞(Forwarding / Bypassing)是用來解決資料冒險(Data Hazard)的核心硬體技術;控制冒險(Control Hazard)則依賴分支預測(Branch prediction)、延遲轉移(Delayed branch)或清空管線(Flushing)。
-
選項分析:
- (a) 錯誤:Pipelining 能提升吞吐量(Throughput),但無法減少單一指令的完成時間(Latency)。
- (b) 錯誤:多週期(Multi-cycle)實作因不同週期可分時共用硬體,允許可使用單一記憶體(Unified memory)存放指令與資料,但並非「強制必須(requires)」只能使用單一記憶體;若架構採用哈佛架構(分開的 Instruction/Data Memory)亦可實作多週期。此處敘述過於絕對且非 Multi-cycle 的定義本質。
- (c) 正確:管線越深(Depth 越大),指令之間重疊階段越多,分支判斷與寫回的級數差拉大,使得各種 Hazards(特別是 Branch Penalty 與 Load-Use Stall)所損失的 Clock cycles 增加,即增加冒險的衝擊。
- (d) 錯誤:Forwarding 是用來解決資料冒險(Data Hazard),而非控制冒險(Control Hazard)。
-
解題技巧:
牢記兩大對比:- Forwarding Data Hazard。
- Pipelining 改善 Throughput,但不改善(甚至稍微增加)Latency。
-
【答案】:(c)
(3) Which of the following statement is true?
-
核心觀念:
多媒體資料表示法與壓縮格式。- 失真壓縮(Lossy Compression):利用人類視覺或聽覺心理感知極限去除冗餘資訊,壓縮率高但無法無失真還原(如 JPEG、MP3、MPEG)。
- 無失真壓縮(Lossless Compression):解壓縮後能 100% 還原原始資料(如 PNG、GIF、FLAC、ZIP)。
- 像素(Pixel, Picture Element):數位影像組成的最小基本單元。
- DPI(Dots Per Inch):每英吋點數,主要衡量列印或印刷解析度;螢幕顯示器的解析度規格通常以總像素量(如 )或 PPI(Pixels Per Inch)表示。
-
選項分析:
- (a) 錯誤:標準 JPEG(Joint Photographic Experts Group)採用離散餘弦轉換(DCT)與量化,屬於失真壓縮(Lossy compression)。
- (b) 錯誤:MP3(MPEG-1 Audio Layer III)利用心理聲學模型去除人耳不敏感的頻率,屬於失真壓縮(Lossy compression)。
- (c) 正確:Pixel(像素)為二維數位點陣影像中不可再分割的最小取樣單位(Smallest addressable unit)。
- (d) 錯誤:DPI(Dots Per Inch)主要用於印表機/印刷品的物理輸出解析度;顯示器使用 PPI(Pixels Per Inch)或原生像素維度(Pixel resolution)。
-
解題技巧:
常見影像與音訊格式分類:- 圖片:JPEG(失真)、PNG/BMP/GIF(無失真)。
- 音訊:MP3/AAC(失真)、FLAC/ALAC/WAV(無失真)。
-
【答案】:(c)
(4) Which of the following interface/protocol does not transmit digital data?
-
核心觀念:
常見視訊與通訊傳輸介面的訊號型態(類比 vs. 數位)。- D-Sub(D-subminiature,常見為 DE-15 / VGA 介面):傳輸的是類比訊號(RGB 類比電壓 + 水平/垂直同步類比訊號)。
- HDMI(High-Definition Multimedia Interface):全數位高解析度影音傳輸介面(採用 TMDS 數位訊號編碼)。
- Bluetooth:無線數位通訊協定,傳輸封包化的數位資料。
- DVI(Digital Visual Interface):主要規範為數位視訊傳輸(DVI-D 為純數位,DVI-I 包含數位與類比,但核心設計與規範本質即為數位傳輸協定)。
-
選項分析:
- (a) 錯誤:HDMI 是標準數位介面,傳輸數位影音資料。
- (b) 錯誤:Bluetooth 是數位無線通訊協定。
- (c) 正確:D-Sub(VGA 介面)專用於傳輸類比視訊訊號(Analog signal),不傳輸數位資料。
- (d) 錯誤:DVI 主要傳輸數位視訊訊號。
-
解題技巧:
電腦螢幕輸出接頭演進:VGA(D-Sub,純類比) DVI(數位/類比相容) HDMI / DisplayPort(純數位高速串列傳輸)。 -
【答案】:(c)
(5) Which of the following statement is true?
- 核心觀念:
軟體工程中的統一塑模語言(Unified Modeling Language, UML)。
第 2 題
(7) Which of the following statement is true?
(a) MongoDB is a persistence technology
(b) jQuery is a back-end technology
(c) Express.js is client-end technology
(d) None of the above
(8) What is (-128) 10 in two's complement?
(a) 01111111
(b) 11111111
(c) 10000000
(d) 11111110
(9) Which of the following statement is false?
(a) It makes no sense to implement a write-through scheme in a Virtual memory
(b) On a data cache miss, the system first stalls the CPU pipeline, fetches data in memory, and restart instruction fetch
(c) Write back refers to on data-write hit, just update the block in cache and write back to memory when a dirty block is replaced.
(d) In order to reduce to operation time of a write-through cache, a write buffer is used to hold data waiting to be written to memory.
(10) Which of the following is not a video container format?
(a) H.264
(b) MP4
(c) AVI
(d) Ogg
(11) In order to persist the data, which of the following memory needs to be recharged?
(a) ROM
(b) SRAM
(c) DRAM
(d) Flash Memory
(12) How many bits are required to address 8G bytes memory?
(a)16
(b)32
(c)64
(d)128
(13) Which of the following programming language does not need a compiler?
(a)Java
(b)JavaScript
(c) Python
(d)C++
(14) Which of the following software is responsible for assembling all necessary functions from required libraries and source code?
(a)loader
(b)linker
(c)assembler
(d)interpreter
登入後即可作答並保存紀錄。
(7) Which of the following statement is true?
核心觀念
本題考查不同軟體技術在系統架構中的角色:
- Persistence technology:負責資料持久化,使資料在程式結束或系統重啟後仍能保存。
- Front-end technology:在使用者端瀏覽器執行。
- Back-end technology:在伺服器端執行,處理資料、商業邏輯與 API。
選項分析
-
(a) MongoDB is a persistence technology:正確。
MongoDB 是文件導向資料庫,能將資料持久儲存在磁碟中,因此屬於資料持久化技術。 -
(b) jQuery is a back-end technology:錯誤。
jQuery 是 JavaScript 函式庫,主要在瀏覽器端執行,屬於前端技術。 -
(c) Express.js is client-end technology:錯誤。
Express.js 是建立在 Node.js 上的伺服器端 Web framework,主要用於撰寫後端 API 與路由處理。 -
(d) None of the above:錯誤。
(a) 已經是正確敘述,因此不能選此項。
解題技巧
看到 MongoDB、MySQL、PostgreSQL 等資料庫,通常可聯想到資料持久化;看到 jQuery,則應聯想到瀏覽器端前端開發;Express.js 則屬於 Node.js 後端生態系。
【答案】(a)
(8) What is in two's complement?
核心觀念
位元二補數的表示範圍為:
題目選項皆為 8 位元,因此範圍為:
因此 正好是 8 位元二補數的最小值。
解題方法
在 8 位元二補數中:
二補數的最小負數 直接表示為:
也可由二補數規則理解:
- 無法以 8 位元有號二補數表示。
- 8 位元中,符號位為 ,其餘位元為 的特殊形式即代表 。
選項分析
-
(a) 01111111:錯誤。
符號位為 ,代表正數 。 -
(b) 11111111:錯誤。
其值為 。 -
(c) 10000000:正確。
其值為 8 位元二補數的最小值 。 -
(d) 11111110:錯誤。
其值為 。
解題技巧
記住 8 位元二補數的兩個邊界:
【答案】(c)
(9) Which of the following statement is false?
核心觀念
本題考查快取記憶體(cache)與虛擬記憶體(virtual memory)的寫入策略:
- Write-through:資料寫入 cache 的同時,也立即寫入主記憶體。
- Write-back:資料先只更新 cache,等該 cache block 被替換時,若標記為 dirty,才寫回主記憶體。
- Write buffer:暫存尚未完成寫入主記憶體的資料,以降低 CPU 等待時間。
- Cache miss:所需資料不在 cache 中,必須從較低層記憶體載入。
選項分析
-
(a) It makes no sense to implement a write-through scheme in a Virtual memory:正確。
虛擬記憶體的低層儲存通常是磁碟或 SSD,速度遠低於主記憶體。若每次寫入都立即同步到磁碟,會造成極大的效能負擔,因此虛擬記憶體通常採用類似 write-back 的延後寫回策略。 -
(b) On a data cache miss, the system first stalls the CPU pipeline, fetches data in memory, and restart instruction fetch:錯誤。
data cache miss 發生時,CPU 會暫停或等待管線,從較低層記憶體載入資料,接著重新執行被中斷的指令或重新嘗試資料存取。正確描述應是恢復該指令的執行,不是重新開始 instruction fetch。 -
(c) Write back refers to on data-write hit, just update the block in cache and write back to memory when a dirty block is replaced:正確。
這正是 write-back cache 的定義。寫入命中時只更新 cache block,並將 dirty bit 設為 ;該 block 被替換時才寫回主記憶體。 -
(d) In order to reduce the operation time of a write-through cache, a write buffer is used to hold data waiting to be written to memory:正確。
write-through 每次寫入都必須同步更新主記憶體,若 CPU 等待寫入完成會降低效能。write buffer 可暫存資料,讓 CPU 先繼續執行。
解題技巧
看到「cache miss」時,標準流程是:
【答案】(b)
(10) Which of the following is not a video container format?
核心觀念
影片檔案通常包含兩個不同層次:
- Container format(容器格式):負責封裝影像、聲音、字幕與 metadata,例如 MP4、AVI、Ogg。
- Video codec(視訊編碼格式):負責壓縮與解壓縮影像資料,例如 H.264、H.265、AV1。
選項分析
-
(a) H.264:正確答案。
H.264 是視訊編碼標準,不是容器格式。 -
(b) MP4:錯誤。
MP4 是常見的影片容器格式,可封裝 H.264 影像與 AAC 聲音。 -
(c) AVI:錯誤。
AVI 是 Microsoft 制定的影片容器格式。 -
(d) Ogg:錯誤。
Ogg 是多媒體容器格式,可封裝影像、聲音等資料。
解題技巧
判斷方式是區分「裝資料的盒子」與「壓縮資料的方法」:
- MP4、AVI、Ogg:容器。
- H.264:編碼器。
【答案】(a)
(11) In order to persist the data, which of the following memory needs to be recharged?
核心觀念
記憶體可依是否需要持續供電與是否需要週期性更新區分:
- Volatile memory:斷電後資料消失。
- Non-volatile memory:斷電後仍能保存資料。
- DRAM:電容會漏電,必須週期性 refresh,才能維持資料。
- SRAM:使用正反器保存資料,不需週期性 refresh,但仍屬揮發性記憶體。
選項分析
-
(a) ROM:錯誤。
ROM 是非揮發性記憶體,不需要週期性充電或 refresh。 -
(b) SRAM:錯誤。
SRAM 不需要週期性 refresh,資料只要持續供電即可維持。 -
(c) DRAM:正確。
DRAM 使用電容儲存 bit,電荷會逐漸漏失,因此必須定期重新充電,也就是 refresh。 -
(d) Flash Memory:錯誤。
Flash 是非揮發性記憶體,不需要持續供電即可保存資料。
解題技巧
看到「需要 recharge/refresh 才能維持資料」,直接聯想到 DRAM。SRAM 雖然需要供電,但不需要週期性 refresh。
【答案】(c)
(12) How many bits are required to address 8G bytes memory?
核心觀念
若記憶體以 byte 為最小定址單位,所需位址位元數為:
通常表示:
因此需要:
選項分析
- (a) 16:錯誤。
16 位元最多定址:
第 3 題8 分
- (8%) Rewrite the following program so that it computes a greatest common divisor using iteration instead of recursion.
unsigned greatest_common_divisor (unsigned a, unsigned b)
{
if (a > b)
return greatest_common_divisor (a-b, b);
else if (b > a)
return greatest_common_divisor (a, b-a);
else // (a == b)
return a;
}
登入後即可作答並保存紀錄。
核心觀念: 尾遞迴轉迭代(Tail Recursion to Iteration)、減法版歐幾里得演算法(Euclidean Algorithm)
改寫思路:
原遞迴函式屬於尾遞迴(tail recursion),每次呼叫只做比較與減法,並將更新後的 (a, b) 傳入下一層,直到 a == b 時回傳 a。改寫為迭代版本時,只需使用 while (a != b) 迴圈取代遞迴呼叫:
- 迴圈條件:當
a != b時持續執行;當a == b時結束迴圈。 - 狀態更新:若
a > b,將a更新為a - b;否則(b > a)將b更新為b - a。 - 回傳值:迴圈終止時
a與b相等,回傳a即為最大公因數。
迭代版程式碼:
unsigned greatest_common_divisor(unsigned a, unsigned b) {
while (a != b) {
if (a > b)
a -= b;
else
b -= a;
}
return a;
}
第 4 題7 分
- (7%) The following is a piece of code written by a programming language in an asynchronous way, what is the output order of A, B, and C? (Assuming that fs.readFile and fs.writeFile are I/O operations and take relative longer time to complete than other operations)
const fs = require("fs");
let john = {
id: 1031,
name: "John",
age: 18
};
fs.writeFile('john.json', JSON.stringify(john), function() {
console.log('A');
fs.readFile('john.json', function(data){
console.log('B');
})
});
console.log('C');
登入後即可作答並保存紀錄。
核心觀念: Node.js 的非同步 I/O(Asynchronous I/O)、回呼函式(Callback Function)巢狀結構與事件循環(Event Loop)。
執行流程分析:
-
同步初始化與變數宣告
const fs = require("fs");載入 Node.js 檔案系統模組,並建立物件john。 -
啟動非同步寫入
fs.writeFile
呼叫fs.writeFile('john.json', JSON.stringify(john), ...)將john轉為 JSON 字串後寫入john.json。由於fs.writeFile為非同步 I/O 操作,主執行緒不會等待寫入完成,而是立即繼續往下執行。 -
執行同步輸出
console.log('C')
主執行緒接著執行最後一行的console.log('C');,屬於同步操作,因此C必定最先輸出。 -
執行
fs.writeFile的回呼函式
待主執行緒的同步程式碼執行完畢,且底層非同步寫入完成後,事件循環會取出fs.writeFile的回呼函式執行:
第 5 題10 分
- (10%) Web Assembly is a binary instruction format for a stack-based virtual machine intended to be embedded in any browser. Web Assembly is designed as a portable target for compilation of any high-level programming language.
(1) According to the description above, what is the key benefit of Web Assembly?
(2) Please propose/sketch an application or a system that is straightforward to implement based on Web Assembly but is not easy to realize before the birth of Web Assembly?
登入後即可作答並保存紀錄。
核心觀念: WebAssembly (Wasm) 的設計特性、核心優勢與典型應用架構。
(1) WebAssembly 的關鍵優勢
依據題幹對 WebAssembly 的定義——「嵌入瀏覽器的堆疊式虛擬機二進位指令格式」與「任何高階語言的可移植編譯目標」,其核心優勢如下:
- 跨語言支援與程式碼複用(Portability & Language Independence):
WebAssembly 被設計為高階程式語言的可移植編譯目標,使瀏覽器不再只能執行 JavaScript。開發者可使用 C、C++、Rust、Go 等語言撰寫核心邏輯,或直接將既有的桌面端函式庫與引擎編譯為.wasm模組,在任何支援 Wasm 的現代瀏覽器上跨平台運行。 - 接近原生程式的執行效能(High Performance):
相較於純文字格式的 JavaScript 需經過詞法/語法分析與動態型別最佳化,Wasm 採用精簡的二進位指令格式(binary instruction format)與堆疊式虛擬機架構,檔案體積小、下載與解碼速度快,且容易被瀏覽器即時編譯(JIT)為高效機器碼,適合計算密集型任務。 - 沙盒安全與瀏覽器整合性(Sandbox Security & Interoperability):
Wasm 模組在瀏覽器的記憶體安全沙盒中執行,無法直接存取主機系統資源,必須透過 JavaScript 膠水程式碼(glue code)與 Web API(如 WebGL、Web Audio、DOM)互動,兼顧安全性與網頁整合能力。
(2) 應用系統提案:瀏覽器端即時影音剪輯與特效系統(或大型 3D 遊戲引擎)
以「瀏覽器端非線性影音剪輯與即時濾鏡系統」(類似網頁版 Premiere / Figma 級計算應用)為例:
-
Wasm 出現前的困難(純 JavaScript 瓶頸):
- 運算效能不足: 影片解碼(如 H.264/HEVC)、逐幀像素處理、音訊混音與 FFT 頻譜運算屬於高度計算密集型任務。JavaScript 的動態型別與垃圾回收(GC)機制容易造成影格率不穩與延遲。
- 既有生態系無法直接複用: 業界成熟的影音編解碼庫(如 FFmpeg)與影像處理庫(如 OpenCV)皆以 C/C++ 撰寫,若要人工改寫為 JavaScript,工程成本極高且效能難以達標,過去通常只能將檔案上傳至後端伺服器處理,或要求使用者安裝桌面軟體。
-
基於 WebAssembly 的系統設計草圖(System Sketch):
- 核心運算層(Wasm 模組):
將 C/C++ 撰寫的 FFmpeg 編解碼器與自訂影像濾鏡演算法,透過 Emscripten 工具鏈編譯為.wasm檔案,負責視訊解碼、畫格合成、特效運算與匯出編碼。
- 核心運算層(Wasm 模組):
第 6 題10 分
- (10%) What are the computational complexities for the following mechanism? (1) Worst case of Mergesort (2) Average case of Insertion Sort (3) Worst case of Heapsort (4)Deleting the whole Circularly Linked List
登入後即可作答並保存紀錄。
核心觀念: 演算法的時間複雜度分析。
題目要求計算四個不同操作或演算法的時間複雜度:Mergesort 的最壞情況、Insertion Sort 的平均情況、Heapsort 的最壞情況,以及刪除整個循環鏈結串列的操作。
時間複雜度表示法: 我們通常使用大 O 符號 () 來表示時間複雜度,它描述了演算法執行時間隨輸入規模 增長而增長的趨勢。
(1) Worst case of Mergesort (合併排序的最壞情況時間複雜度):
- Mergesort (合併排序) 是一種分治 (Divide and Conquer) 演算法。它的基本思想是:
- 將列表分成兩半。
- 遞迴地對兩半進行排序。
- 將兩個已排序的半部分合併成一個已排序的列表。
- 合併 (Merge) 操作: 合併兩個已排序的列表需要線性時間,即 ,其中 和 是兩個列表的大小。
- 遞迴關係: 設 為排序 個元素的 Mergesort 所需時間。則 。
- 時間複雜度: 使用主定理 (Master Theorem) 或遞迴樹法 (Recursion Tree Method) 分析,可以得出 Mergesort 的時間複雜度在所有情況下(最好、平均、最壞)都是 。這是因為每次遞迴都會將問題規模減半,而合併步驟始終是線性的。
- 【答案】
(2) Average case of Insertion Sort (插入排序的平均情況時間複雜度):
- Insertion Sort (插入排序) 是一種簡單的排序演算法,它通過將元素逐個插入到已排序的序列中的正確位置來完成排序。
- 操作: 對於列表中的第 個元素,它需要與前面 個元素進行比較和可能的交換,直到找到正確的位置。
- 最好情況: 當列表已經排序時,每個元素只需與前一個元素比較一次,時間複雜度為 。
- 最壞情況: 當列表完全逆序時,第 個元素需要與前面所有 個元素比較,總比較次數和交換次數為 ,時間複雜度為 。
- 平均情況: 在隨機順序的輸入下,平均需要比較和移動的元素數量約為總數的一半。因此,平均情況下的時間複雜度與最壞情況相同。
- 【答案】
(3) Worst case of Heapsort (堆積排序的最壞情況時間複雜度):
- Heapsort (堆積排序) 是一種比較排序演算法,它利用了堆積 (Heap) 資料結構。
- 建堆 (Build Heap): 將無序的數組構建成一個最大堆(或最小堆)需要 的時間。
- 排序過程:
- 將堆頂元素(最大值)與堆的最後一個元素交換。
- 將堆的大小減一。
- 對新的堆頂元素進行下沉 (heapify) 操作,以恢復堆的性質。
- 重複以上步驟直到堆的大小為 1。