免費詳解 / 中山 / 軟體 / 102

102 中山資工所考古題解答|軟體逐題詳解

102 中山資工所軟體考古題的逐題詳解,共 9 題,免費公開。

逐題詳解

120%

Multiple-choice questions (each subquestion deserves 4%). There may be ZERO or MORE correct answers in each subquestion. If there is no correct answer, please give the answer "None".

(1) Build a binary search tree for the input sequence 12, 5, 7, 18, 19, 15, 14, 6, 13. It is assumed that the tree root is on level 1. (A) There are five levels in the tree. (B) 14 is on level 3. (C) If we want to search 16, the number of required node comparisons is 3. (D) The subtree rooted at 15 has 3 nodes (including 15).

(2) Which statement(s) is correct for an AVL tree? (A) The absolute value of the level difference of any two leaves is at most one. (B) The absolute value of the height difference of any two subtrees on the same level is at most one. (C) A deletion needs at most two rotation operations to preserve an AVL tree to be a height-balanced tree. (D) After a new node is inserted, the tree height will not increase if rotation operations are performed.

(3) In a stack structure, let u denote a push operation and o denote a pop operation. After a sequence of stack operations, consisting of 3 pushes and 3 pops, an input sequence 123 may change its order. For example, after uouuoo is performed, 123 will become 132. Which sequence(s) cannot be obtained from input 123 by stack operations? (A) 213 (B) 231 (C) 312 (D) 321.

(4) Which statement(s) is correct for binary search on a sequence? (A) The sequence must be sorted. (B) Binary search can be implemented by an array. (C) Binary search can be implemented by a linked list. (D) The hashing technique is an implementation of binary search.

(5) Which statement(s) is correct for arithmetic expressions? (A) There is no parenthesis in a postfix expression. (B) The first symbol in a prefix expression must be an operator. (C) The first symbol in a postfix expression must be an operator. (D) The amount of operands in a prefix is more than that of operators.

(1) 依序插入:12 → 5(左)→ 7(5 右)→ 18(右)→ 19(18 右)→ 15(18 左)→ 14(15 左)→ 6(5→7 左)→ 13(14 左)

567121314151819

(A) 最深的 13 在 level 5 → T

(B) 14 在 level 4 → F

(C) 找 16:12、18、15 三次比較後落空 → T

(D) 15 的 subtree 為 15、14、13 → T

(A)(C)(D)

(2) (A) AVL 只限制每個 node 左右 subtree 高度差;leaf 的 level 可差 2 以上 → F

(B) 不同 node 底下、同一層的兩個 subtree 高度可差 2 以上 → F

(C) delete 的不平衡會往 root 方向連鎖,最壞 \(O(\log n)\) 次 rotation → F

(D) insert 後有做 rotation 時,該 subtree 高度回到插入前,整棵樹不變高 → T

(D)

(3) 3 push、3 pop 能得到的輸出:uououo → 123、uouuoo → 132、uuoouo → 213、uuouoo → 231、uuuooo → 321

要先輸出 3,1、2、3 都已在 stack 內(上到下 3,2,1),pop 3 之後先出 2,不可能是 1 → 312 不行

(C)

(4) (A) T (B) array 可取中間元素 T (C) linked list 取不到中間元素,要逐一走訪 F (D) hash 直接算位置 F

(A)(B)

(5) (A) postfix 順序已由位置決定 T

(B) prefix 為「運算子 運算元 運算元」 T

(C) postfix 第一個符號是運算元 F

(D) 二元運算子的 expression,operands 比 operators 多 1 T

(A)(B)(D)

(D) 以二元運算子的算術式為準;含 unary operator(例:prefix + - 3 9 兩個運算元、兩個運算子)時不成立。

210%

Printed results in C codes (each subquestion deserves 5%). What are printed in each of the following program segments?

(1)

int a[]={5,7,9,11,13};
int *p;
int i=2;
p=a;
*(p++) = ++i;
printf("%d %d %d %d %d",a[0],a[1],a[i++],*p,*(p+1));

(2)

int b=26;
printf("%d", ((b >> 3) << 2) & ((b <<2) >> 3));

(1) ++i → \(i=3\);*(p++) 先用舊的 \(p=a\) → \(a[0]=3\),\(p\) 指向 \(a[1]\)

\(a=\{3,7,9,11,13\}\)

\(a[0]=3\),\(a[1]=7\),\(a[i++]=a[3]=11\),*p \(=a[1]=7\),*(p+1) \(=a[2]=9\)

3 7 11 7 9

(2) \(26=11010_2\)

\((26\gg3)\ll2=3\ll2=12=01100_2\)

\((26\ll2)\gg3=104\gg3=13=01101_2\)

\(12\ \&\ 13=01100_2=12\)

12

310%

Two-way insertion sort. Suppose the output sorted sequence is increasing. The two-way insertion sort is a modification of the simple insertion sort, described as follows. After read the input elements, a separate output array a[0], a[1], a[2], ... a[n-1] is used to store the sorted sequence. This output array acts as a circular structure, that is, the right position of a[i] is a[i+1] if 0 ≤ i ≤ n-2, and the right position of a[n-1] is a[0]. The first input element is put into a[0] initially. Once a contiguous group of elements are in the array, room for a new input element is made by shifting all smaller elements one step to the left or all larger elements one step to the right. The choice of left-shift or right-shift to perform depends on which would cause the smallest amount of shifts. Use the following 6 input elements to illustrate how this algorithm works. You have to show the content of the output array after each input element is inserted into the array.

27, 35, 43, 31, 29, 33.

\(n=6\),a[0]~a[5] 當環狀陣列,每次比較「比它小的整批左移」與「比它大的整批右移」,搬得少的那邊

插入a[0]a[1]a[2]a[3]a[4]a[5]搬動
2727放 a[0]
352735比它大的 0 個,右移 0 次
43273543右移 0 次
3131354327左移 27(1 次)\(\lt\) 右移 35、43(2 次)
293135432729左移 27(1 次)\(\lt\) 右移 31、35、43(3 次)
33313335432729右移 35、43(2 次)\(\lt\) 左移 27、29、31(3 次)

由 a[4] 起繞一圈讀出:27, 29, 31, 33, 35, 43

a = [31, 33, 35, 43, 27, 29]

410%

Huffman tree. Suppose seven symbols A, B, C, D, E, F, G with frequencies 8, 15, 1, 6, 15, 3, 7, respectively, are given. You have to obey the following rules for constructing the Huffman tree: (1) The label of each leaf node is a single symbol. The label of each internal node is the concatenation of the labels of its left child and right child. (2) When two nodes are merged, always set the node of label with less lexical order as the left child, and the other as the right child. (3) If more than two nodes have the same least frequency, then you have to merge the two that have the least and the second least label in lexical order. Please draw the full Huffman tree.

① C(1)+F(3) → CF(4)

② CF(4)+D(6) → CFD(10)(CF \(\lt\) D,CF 在左)

③ G(7)+A(8) → AG(15)(A 在左)

④ 最小是 CFD(10);其次 15 有 AG、B、E 三個並列,取 label 最小的 AG → AGCFD(25)(AG 在左)

⑤ B(15)+E(15) → BE(30)

⑥ AGCFD(25)+BE(30) → AGCFDBE(55)

000110011101A 8AG 15G 7AGCFD 25C 1CF 4F 3CFD 10D 6AGCFDBE 55B 15BE 30E 15

碼(左 0 右 1):A 000、G 001、C 0100、F 0101、D 011、B 10、E 11

總長 \(8\cdot3+7\cdot3+1\cdot4+3\cdot4+6\cdot3+15\cdot2+15\cdot2=139\) bits。

514%

True-false questions (each subquestion deserves 2%). Mark either ‘O’ or ‘X’ to respectively answer “yes” or “no” for each subquestion. You will get -2 point for each wrong answer until no point can be deducted from this question.

(1) The need-to-know principle dictates that programs, users, and even systems should be given just sufficient privileges to perform their tasks. This principle is very critical for system protection, which can prevent the mischievous, intentional violation of an access restriction by a user.

(2) A deadlock situation must arise if any of the following four conditions holds in a computer system: mutual exclusion, hold and wait, no preemption, and circular wait. Therefore, to vanquish the deadlock, we have to see what conditions cause that deadlock and then try to conquer each of them.

(3) We can realize a dynamic relocation by using a relocation register in memory management. For example, suppose that the CPU asks a logical address of 123 and the relocation register has a value of 1877. Then, the physical address will be 2000.

(4) A trap door may be included in a compiler. Therefore, the compiler would generate the standard object code as well as a trap door. However, this activity can be still found by conducting a very careful search of the source code of the compiled program.

(5) An attack that one participant in a communication pretends to be someone else is called the man-in-the-middle attack. Such an attack breaches the correctness of identification. A cracker can use this attack to gain access that he/she would not normally be allowed or escalate his/her privileges.

(6) RAID level 0+1 refers to a combination of RAID levels 0 and 1, where RAID 0 provides the performance, while RAID 1 supports the reliability. Generally speaking, this level provides better performance than RAID 5. It is common in environments where both performance and reliability are important.

(7) Location independence and location transparency are two related notions regarding name mappings in a distributed file system. A location-transparency naming scheme is a dynamic mapping, since it can map the same file name to different locations at two different times. Therefore, location transparency is a stronger property than location independence.

(1) need-to-know:只給剛好夠用的權限,protection 的核心原則 → O

(2) 四個條件要同時成立才會 deadlock,不是任一個成立就會 → X

(3) \(123+1877=2000\) → O

(4) trap door 在 compiler 裡,被編譯的程式的 source code 看不出來,要查 compiler 的 source code → X

(5) 一方假冒成別人是 masquerading;man-in-the-middle 是攻擊者插在雙方中間,兩邊都假扮 → X

(6) RAID 0+1 兼顧效能與可靠度,不必為寫入算 parity,效能比 RAID 5 好 → O

(7) dynamic mapping(同一檔名在不同時間對應不同位置)是 location independence,它才是較強的性質;題目兩個名詞對調了 → X

(1)O (2)X (3)O (4)X (5)X (6)O (7)X

610%

Choice questions (each subquestion deserves 2%). Select the BEST ONE ANSWER for each subquestion from the following box:

A. page faultB. processC. page replacement
D. wormE. virusF. authentication
G. Trojan horseH. encryptionI. class
J. bnodeK. demand pagingL. inode
M. threadN. cnodeO. decryption

(1) The smallest unit of CPU utilization, which can be executed independently by OS

(2) The technique that loads pages only as they are needed

(3) A code fragment embedded in a legitimate program, which is designed to self-replicate & infect other programs

(4) The security technique that supports nonrepudiation

(5) A file-control block in most UNIX file systems

(1) CPU 排程與獨立執行的最小單位 → thread

M

(2) 用到才載入 page → demand paging

K

(3) 藏在合法程式內、自我複製並感染其他程式(worm 是獨立程式,Trojan horse 不自我複製) → virus

E

(4) 數位簽章讓送出者無法否認 → authentication

F

(5) UNIX 的 file-control block → inode

L

76%

Disk scheduling. Suppose that you are given a disk queue with requests for I/O to blocks on cylinders 98, 183, 37, 122, 14, 124, 65, and 67. Let the disk head start at cylinder 53. Please show the disk scheduling result by (1) The shortest-seek-time-first algorithm (3%) (2) The SCAN algorithm (3%)

(1) SSTF 每次取離目前位置最近的

53 → 65 → 67 → 37 → 14 → 98 → 122 → 124 → 183

\(12+2+30+23+84+24+2+59=236\)

順序 65, 67, 37, 14, 98, 122, 124, 183 共 236 cylinders

(2) SCAN 磁頭先往小號方向掃到 0,再折返往大號方向(cylinder 0~199)

53 → 37 → 14 → 0 → 65 → 67 → 98 → 122 → 124 → 183

\((53-0)+(183-0)=236\)

順序 37, 14, (0), 65, 67, 98, 122, 124, 183 共 236 cylinders

若先往大號方向,則 53 → 65 → 67 → 98 → 122 → 124 → 183 → (199) → 37 → 14。

810%

Distributed synchronization. (1) In a distributed system, deciding the event ordering is usually difficult. Why? (2%) (2) Let A, B, C be events and ‘→’ denote the happen-before relation between two events. Please explain the three principles of the happen-before relation in a distributed system using the above notations. (6%) (3) What is an atomic transaction? (2%)

(1) 沒有共用記憶體,也沒有共同的 clock;各 site 只靠 message 溝通,延遲不定、本地 clock 會漂移,無法用物理時間為所有事件排出全域順序

(2) happened-before(→):

① 同一個 process 內,A 先於 B 執行 → \(A\to B\)

② A 是某 process 送出 message,B 是另一 process 收到同一 message → \(A\to B\)

③ transitivity:\(A\to B\) 且 \(B\to C\) → \(A\to C\)

A→B、B→A 都不成立的兩個事件是 concurrent。

(3) atomic transaction:一串 read/write 操作視為單一工作單位,要嘛全部完成(commit),要嘛全部沒發生(abort,已做的部分 rollback)

910%

Memory management. (1) What is a reentrant code? (2%) (2) How does the CPU know whether a page is available or not from the page table? (2%) (3) Suppose that it takes 20 nanoseconds to search the TLB (translation look-aside buffer) and 100 nanoseconds to access memory. If we want the effective memory-access time no longer than 122 nanoseconds, what is the hit ratio for the TLB? (6%)

(1) reentrant code(pure code):執行時不修改自己的 code,可由多個 process 共用同一份;每個 process 只需各自的 register 與 data

(2) 看 page table entry 的 valid–invalid bit:valid 表示 page 合法且在 memory,可用 frame number;invalid 表示不在 memory(或不在位址空間),硬體觸發 page fault trap

(3) TLB hit:\(20+100=120\) ns;TLB miss:\(20+100+100=220\) ns

\(120h+220(1-h)=220-100h\le122\)

\(h\ge0.98\)

hit ratio 至少 98%

109–115 的詳解也是這樣寫的。

國立中山大學 109–115 的詳解收錄在付費版;106–115 全年度完整詳解共 236 頁,逐題推導。

購買 · NT$ 850 看中山其他免費詳解

其他年度與考科

同一年的其他科

同一科的其他年度

聯絡我們

題目有錯、詳解看不懂,都歡迎來信

想許願補哪一份、對購買有疑問也可以,收到後會盡快回覆。

william.chou.123123@gmail.com