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 左)
(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 兩個運算元、兩個運算子)時不成立。