111 年 國立臺灣大學生物機電系碩士班丙組《計算機概論(A)》
第 1 題10 分
Consider the following logic circuit, derive the function Q in terms of A, B, C, D. (5%). Using the de Morgan's theorem, find the simplest form of the function Q (5%).
🖼️【此處有附圖,請對照原卷】
(邏輯電路:A 與經反相器的 輸入上方的 NAND 閘;經反相器的 與 D 輸入下方的 AND 閘;這兩個閘的輸出再一起輸入一個 NAND 閘,輸出為 Q。)
登入後即可作答並保存紀錄。
核心觀念
本題考查邏輯閘的布林函數表示,以及德摩根定理。閘輸出端的小圓圈代表反相:上方閘與最末閘是 NAND 閘,下方閘是 AND 閘。
德摩根定理為:
解題方法
先依訊號流向,分別寫出上方閘、下方閘的輸出,再代入最末閘。
上方 NAND 閘的輸入為 與 ,故其輸出為:
下方 AND 閘的輸入為 與 ,故其輸出為:
最末 NAND 閘將 與 作為輸入,因此:
第 2 題10 分
Consider the following grammar:
S → AB$ (1)
A → xA (2)
A → B (3)
B → yzB (4)
B → z (5)
a) What are the terminals and non-terminals of this grammar? (5%)
b) Show the parse tree for xyzzz$. (5%)
登入後即可作答並保存紀錄。
核心觀念
文法由非終結符、終結符及產生式構成。非終結符可依產生式繼續展開;終結符是推導完成後留下的符號。句子的推導結果,也可用解析樹呈現:根節點是開始符號,每個內部節點依照一條產生式展開,葉節點由左至右讀出的字串就是句子。
解題方法
(a) 由產生式左側可辨認非終結符;右側出現的符號中,凡不屬於非終結符者都是終結符。題目明確將 $ 寫在產生式中,因此它也是本題文法的終結符。
- 非終結符:
- 終結符:
{x, y, z, $}
(b) 依照開始符號 推導。目標字串在 $ 前是 xyzzz。先由 S → AB$,再讓 產生開頭的 ,接著 ;前一個 產生 yzz,後一個 產生 z:
第 3 題10 分
Using the RSA encryption algorithm, pick the prime numbers and . Find a set of encryption/decryption keys and . (10%)
登入後即可作答並保存紀錄。
核心觀念
RSA 先選兩個質數 ,計算模數 與歐拉函數 。加密指數 必須滿足 ;解密指數 則是 在模 下的乘法反元素,也就是
因此, 除以 的餘數必須為 。
解題方法
題目給定 、,先計算:
接著選一個與 互質的 。取 ,因為 ,符合加密指數條件。
第 4 題10 分
The keys 12, 18, 13, 2, 3, 23, 5 and 15 are inserted into an initially empty hash table of length 10 using open addressing with hash function and linear probing. What is the resultant hash table? (10%)
登入後即可作答並保存紀錄。
核心觀念
本題考查開放定址法中的線性探測。雜湊表長度為 ,索引範圍是 到 。每個鍵先依雜湊函數計算起始位置:
若起始位置已被占用,就依序檢查下一格,直到找到空格為止。探測位置會在表尾循環回表頭,但本題不需要循環。
解題方法
依題目給定的鍵值順序逐一插入;每次遇到碰撞,就往下一個索引探測。
| 插入鍵值 | 起始位置 | 探測過程 | 放入位置 |
|---|---|---|---|
| 索引 為空 | |||
| 索引 為空 | |||
| 索引 為空 | |||
| 索引 已占用,索引 為空 | |||
| 索引 已占用,索引 為空 |
第 5 題10 分
Consider a 10 Mbps Ethernet LAN that has stations attached to a 2.5 km long coaxial cable. Given that the transmission speed is m/sec, the packet size is 128 bytes out of which 30 bytes are overhead, and the efficiency is 59%, answer the following questions.
a) What is the transmission delay? (3%)
b) What is the propagation delay? (3%)
c) What is the effective transmission rate? (4%)
登入後即可作答並保存紀錄。
核心觀念
這題考三種速率/延遲的區別:
- 傳輸延遲:把整個封包的位元送上傳輸媒介所需的時間,公式為「封包位元數 ÷ 傳輸速率」。
- 傳播延遲:訊號沿媒介從一端傳到另一端所需的時間,公式為「媒介長度 ÷ 訊號傳播速度」。
- 有效傳輸率:名目傳輸率經效率折減後,再按封包中真正承載資料的比例計算。
以下將題目的 視為媒介傳送效率,並將 30 bytes overhead 視為不承載有效資料的封包負擔。
解題方法
a) 傳輸延遲
封包大小為 128 bytes,換算成位元:
乙太網路傳輸速率為 ,因此:
b) 傳播延遲
同軸電纜長度為 ,訊號傳播速度為 :
第 6 題10 分
Assume that a 12-bit Hamming codeword consisting of 8-bit data and 4 check bits is , where the data bits and the check bits are given in the following tables. What are the values of A and B? (10%)
Data bits
| 1 | 1 | 0 | A | 0 | 1 | 0 | 1 |
Check bits
| B | 0 | 1 | 0 |
登入後即可作答並保存紀錄。
核心觀念
12 位元 Hamming code 的檢查位元放在由右至左編號的第 位,分別是 。採用偶同位時,每個檢查位元所涵蓋的位置,其位元總和必須為偶數;等價地說,這些位元的 XOR 結果為 。
依 12 位元標準位置排列,題幹字串中重複的 視為排版誤植,位置如下:
| 位置 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 位元 |
解題方法
先利用 的檢查範圍求 。 檢查位置 ,也就是:
第 7 題10 分
The preorder traversal sequence of a binary search tree is:
30, 20, 10, 15, 25, 23, 39, 35, 42
a) Draw the binary search tree. (5%)
b) What is the postorder traversal sequence of the same tree? (5%)
登入後即可作答並保存紀錄。
核心觀念
二元搜尋樹(BST)中,每個節點都滿足:左子樹的鍵值小於該節點,右子樹的鍵值大於該節點。
前序走訪順序為「根 → 左子樹 → 右子樹」,所以序列的第一個值是根。重建時,依 BST 的大小規則將後續節點分到左右子樹;後序走訪則是「左子樹 → 右子樹 → 根」。
解題方法
前序序列為:
第一個值 是根。接著依大小關係建立左右子樹:
- 小於 的節點屬於左子樹:。
- 大於 的節點屬於右子樹:。
- 左子樹以 為根。 小於 ,位於左側; 大於 ,位於右側。 小於 、但大於 ,因此是 的右子節點; 小於 ,因此是 的左子節點。
- 右子樹以 為根。 小於 ,位於左側; 大於 ,位於右側。
a) 二元搜尋樹
第 8 題10 分
Find the arithmetic expression for the following assembly code. (10%)
MOV AX, A
MOV BL, B
ADD AX, 2
MOV CL, 3
SUB BL, CL
DIV BL
MOV SUM, AL
登入後即可作答並保存紀錄。
核心觀念
本題考查 8086 組合語言的資料寬度、算術指令,以及 DIV 的隱含被除數與商、餘數位置。
DIV BL 的除數是 8 位元暫存器 BL。執行 8 位元除法時,處理器以 AX 為被除數,將商存入 AL、餘數存入 AH。
解題方法
依序追蹤指令執行後的暫存器值:
MOV AX, A:令AX = A。MOV BL, B:令BL = B。ADD AX, 2:令AX = A + 2。MOV CL, 3、SUB BL, CL:令BL = B - 3。DIV BL:以AX除以BL,商存入AL。MOV SUM, AL:將商存入SUM。
第 9 題10 分
Write a program which sorts the following data in ascending order using the selection sort algorithm. You may use any computer programming language for this problem. (10%)
| 20 | 12 | 10 | 15 | 2 |
|---|
登入後即可作答並保存紀錄。
核心觀念
選擇排序(selection sort)每一回合都在尚未排序的區間中找出最小值,並將它與區間最左側的元素交換。完成一回合後,最左側的位置便確定為目前區間的最小值;接著縮小未排序區間,直到全部排好。
解題方法
原始資料為 。依序找出每一輪未排序區間的最小值:
| 回合 | 未排序區間 | 最小值 | 交換後的資料 |
|---|---|---|---|
| 1 | 2 | ||
| 2 | 10 | ||
| 3 | 12 | ||
| 4 | 15 |
以 Python 實作如下:
第 10 題10 分
A pair of positive integer numbers are called twin primes if they are both prime numbers and the difference between them is 2, i.e., they are consecutive odd numbers and they are prime numbers. (3, 5), (5, 7) and (11, 13) are three examples of such pair of twin prime numbers. Write a program to display all the pairs of twin prime numbers that are less than 10000. You may use any computer programming language for this problem. (10%)
登入後即可作答並保存紀錄。
核心觀念
孿生質數是兩個質數,且相差 。因此只要由小到大檢查每個整數 ,判斷 與 是否皆為質數,就能找出所有孿生質數對。
本題適合使用埃拉托斯特尼篩法。質數 的合數倍數可由其質因數標記;篩到 即可,因為若 是合數,至少有一個因數不大於 。
解題方法
題目要求兩個數都小於 ,所以令上限為 ,建立索引為 到 的布林陣列 is_prime。初始時假設每個數都是質數,再依序將合數標記為 False。
對每個未被標記的質數 ,從 開始標記其倍數。小於 的倍數已會由更小的質因數標記,因此可從 起算。完成篩選後,逐一檢查 和 ;兩者皆為質數時輸出該數對。