Circle Red-Node Triangle Black-Node
Circle Red-Node Triangle Black-Node
天主教輔仁大學 ■學期 補考 考 試 試 題 (共 2 頁第 1 頁)
科目: 演算法 系級組別: 資訊工程學系 考試日期:112 年 6 月 16 日第 2 與 3 節
命題教授: 張信宏 先生(簽章) 112 年 6 月 03 日 需用份數:90 份 總分: 130
(1) (50%) Please use the following insertion order to build four kinds of binary trees.
A 1 2 3 4 5 6 7 8 9 10 11 12
5 3 12 11 7 9 8 2 6 4 10 13
(a) (8%) red-black tree. (Use circle O to represent red-node and triangle △ to represent black- node).
(b) (7%) 234-Tree.
(c) (7%) Splay Tree (note: Total insertions for building a BST are completed and then user will find(11)).
(d) (8%) Please build an AVL tree from A[1] to A[11].
(e) (8%) Please build a segment tree for solving range max query.
(f) (5%) Use the segment tree in (e) and demonstrate how to get max value from index 3 to 10.
(g) (7%) Please build a bit index tree (BIT) for solving range sum query.
(a) (I) (15%) Please demonstrate the SPFA algorithm to solve the shortest path from node 0 to other nodes in
the following graph.
_
(II) (10%) Please demonstrate the Dijkstra algorithm to solve the shortest path from node 0 to other nodes
in the following graph.
(b) (I) (10%) Please use dinic algorithm to find the maximum flow from source node 1 to sink node 6 in the
following directed graph. (II) (3%) Explain “minimum cut is equal to maximum flow. (III) (2%) Explain
“flow conservation property in node 2”?
期中 畢業
天主教輔仁大學 ■學期 補考 考 試 試 題 (共 2 頁第 2 頁)
(3) (40%) Algorithm Design.
(a) (10%) Cars arrive at the train station in the following order. When each car arrives, you can add it to the
beginning or end of the car-chain, or refuse to add it. Please show the longest increasing car-chain you can
arrange?
9 8 12 6 14 10 3 13 1 4
(b) (10%) OPTi indicates optimal sum of a subarray in array A[i] and OPT*(i) indicates max sum of a subarray
with ending at A[i]. Please use Design a O(n) algorithm to find maximum sub-array in the following array
and fill in the OPT(i) and OPT*(i) of following table. The initial values of OPT(i) and OPT*(i) are zero.
A 1 2 3 4 5 6 7 8 9 10 11
1 -3 8 5 -2 6 3 -5 4 -6 7
OPT(i)
OPT*(i)
(c) (10%) Given a double ended queue (dequeue) with permutation of numbers from 1 to n (n≥5), we want to
remove all of the numbers to form a sequence <a1, a2, a3, …,an> that maximizes the alternative sum
(a1-a2+a3…±an), where a1 is the first number removed, a2 is the second number, and so on. Please design
an O(n2) dynamic programming algorithm to generate the optimal sequence for a given permutation <5, 4,
1, 2, 3>.
(d) (10%) Find the articulation points in the following graph. Redraw the graph showing tree edges, back
edges, the DFS number and LOW value assigned to each vertex. For definiteness, start your DFS at
vertex A and whenever the algorithm has a choice of which edge to follow next, pick the edge to the
alphabetically(字典序小的先) first vertex among the vertex choices.