數值方法

advertisement
第1頁共3頁
資料結構
課堂作業四
系級:
座號:
姓名:
一、 (15%) Given a max heap, whose elements are all integer, as follows:
14
11
10
4
k
12
1
8
6
Please answer the following questions:
(1) k =
(2) If we insert two elements into the heap, the first one is 20, and the second
one is 5, please draw the max heap after these insertions.
(3) And then, if we delete two elements from the heap, please draw the max
heap after these deletions.
二、 (15%) Given a binary search tree, whose elements are all integer, as follows:
20
15
k
17
22
24
Please answer the following questions:
(1) k =
(2) If we insert two elements into the tree, the first one is 5, and the second one is
18, please draw the binary search tree after these insertions.
(3) And then, if we delete two elements, 17 and 20, from the binary search tree,
please draw the binary search tree after these deletions.
1
第2頁共3頁
三、 (15%) Given a winner tree for k = 8 as follows:
10
9
20
6
7
9
90
17
15
22
21
17
11
12
95
18
16
38
30
25
50
16
96
20
Please (1) finish the winner tree.
(2) Draw its corresponding loser tree.
(3) If we output two elements from the winner tree, please draw the
restructured winner tree.
四、 (25%) Given a forest as follows:
G
A
B
E
F
J
H
C
K
D
L
I
Please (1) Please show its binary tree representation.
(2) The result of pre-order traversal of the forest is:
(3) The result of in-order traversal of the forest is:
(4) The result of post-order traversal of the forest is:
(5) The result of level-order traversal of the forest is:
2
第3頁共3頁
五、 (25%)
(1) Suppose we have the preorder sequence ABCDEFGHI and the inorder
sequence BCAEDGHFI of the same binary tree. Can you draw the tree? If
not, explain.
(2) Suppose we have the postorder sequence FECHGDBA and the inorder
sequence FECABHDG of the same binary tree. Can you draw the tree? If not,
explain.
(3) Suppose we have the postorder sequence GFDABEC and the inorder
sequence ABDCEFG of the same binary tree. Can you draw the tree? If not,
explain.
(4) Suppose we have the preorder sequence ABDECFG and the postorder
sequence DEBFGCA of the same binary tree. Can you draw the tree? If not,
explain.
(5) Do the inorder and level-order sequences of a binary tree uniquely define the
binary tree? Explain it.
六、 (10%)
(1) The number of distinct binary trees with n nodes is:
(2) Please draw all the distinct binary trees with 3 nodes.
3
Download