判斷題
1.某二叉樹的前序和中序遍歷序列正好一樣,則該二叉樹中的任何結點一定都無左孩子。
2.已知一棵二叉樹的先序遍歷結果是ABC, 則CAB不可能是中序遍歷結果。
3.在一棵二叉搜索樹上查找63,序列39、101、25、80、70、59、63是一種可能的查找時的結點值比較序列。
4.將1、2、3、4、5、6順序插入初始為空的AVL樹中,當完成這6個元素的插入后,該AVL樹的先序遍歷結果是:4、2、1、3、5、6。
5.一棵有124個結點的完全二叉樹,其葉結點個數是確定的。
6.對N(≥2)個權值均不相同的字符構造哈夫曼樹,則樹中任一非葉結點的權值一定不小於下一層任一結點的權值。
7.In a min-heap, all the keys along the path from the root to any leaf node must be in sorted (non-decreasing) order.
8.To find 63 from a binary search tree, one possible searching sequence is {39, 101, 25, 80, 70, 59, 63}.
9.存在一棵總共有2016個結點的二叉樹,其中有16個結點只有一個孩子。
10.將一棵完全二叉樹存於數組中(根結點的下標為1)。則下標為23和24的兩個結點是兄弟。
11.在有N個元素的最大堆中,隨機訪問任意鍵值的操作可以在O(logN)時間完成。
12.對AVL樹中的任一結點,其左子樹的高度一定比其右子樹的高度要高。
13.完全二叉樹中,若一個結點沒有左孩子,則它必是樹葉。
14.完全二叉樹的存儲結構通常采用順序存儲結構。
選擇題
1.在並查集問題中,已知集合元素0~8所以對應的父結點編號值分別是{ 1, -4, 1, 1, -3, 4, 4, 8, -2 }(注:−n表示樹根且對應集合大小為n),那么將元素6和8所在的集合合並(要求必須將小集合並到大集合)后,該集合對應的樹根和父結點編號值分別是多少?
B.4和-5
C.8和-5
D.8和-6
2.The array representation of a disjoint set containing numbers 0 to 8 is given by { 1, -4, 1, 1, -3, 4, 4, 8, -2 }. Then to union the two sets which contain 6 and 8 (with union-by-size), the index of the resulting root and the value stored at the root are:
B.4 and -5
C.8 and -5
D.8 and -6
3.The array representation of a disjoint set is given by { 4, 6, 5, 2, -3, -4, 3 }. If the elements are numbered from 1 to 7, the resulting array after invoking Union(Find(7),Find(1))
with union-by-size and path-compression is:
B.{ 4, 6, 5, 2, -7, 5, 3 }
C.{ 6, 6, 5, 6, -7, 5, 5 }
D.{ 6, 6, 5, 6, 6, -7, 5 }
4.The array representation of the disjoint sets is given by {2, –4, 2, 3, -3, 5, 6, 9, -2}. Keep in mind that the elements are numbered from 1 to 9. After invoking Union(Find(4), Find(6)) with union-by-size, which elements will be changed in the resulting array?
B.a. elements of index 2 and 6
C.a. elements of index 4 and 5
D.a. elements of index 4 and 6
5.In a disjoint set problem, given a set of m elements S = { 1, 2, 3, ..., m } and n ( 0<n<m ) distinct relations, the set S must have __ equivalence classes.
B.exactly n
C.exactly m−n
D.at least m−n
6.已知不相交集合用數組表示為{ 4, 6, 5, 2, -3, -4, 3 }。若集合元素從1到7編號,則調用Union(Find(7),Find(1))
(按規模求並,並且帶路徑壓縮)后的結果數組為:
B.{ 4, 6, 5, 2, -7, 5, 3 }
C.{ 6, 6, 5, 6, -7, 5, 5 }
D.{ 6, 6, 5, 6, 6, -7, 5 }
7.若並查集用樹表示,其中有n個結點,查找一個元素所屬集合的算法的時間復雜度為____。
B.O(n)
C.O(n 2)
D.O(nlog 2n)
8.設樹T的度為4,其中度為1、2、3、4的結點個數分別為4、2、1、1。則T中有多少個葉子結點?
B.6
C.8
D.10
9.三叉樹中,度為1的結點有5個,度為2的結點3個,度為3的結點2個,問該樹含有幾個葉結點?
B.10
C.12
D.13
10.按照二叉樹的定義,具有3個結點的二叉樹有幾種?
B.4
C.5
D.6
11.二叉樹中第5層(根的層號為1)上的結點個數最多為:
B.15
C.16
D.32
12.先序遍歷圖示二叉樹的結果為
B.A,B,D,H,I,E,C,F,G
C.H,D,I,B,E,A,F,C,G
D.H,I,D,B,E,F,G,A,C
13.AVL樹是一種平衡的二叉搜索樹,樹中任一結點具有下列哪一特性:
B.左、右子樹高度差的絕對值不超過1
C.左子樹的高度均大於右子樹的高度
D.左子樹的高度均小於右子樹的高度
14.已知關鍵字序列(5,8,12,19,28,20,15,22)是最小堆(小根堆),插入關鍵字3,調整后得到的最小堆是:
B.3,5,12,19,20,15,22,8,28
C.3,8,12,5,20,15,22,28,19
D.3,12,5,8,28,20,15,22,19
15.由分別帶權為9、2、5、7的四個葉子結點構成一棵哈夫曼樹,該樹的帶權路徑長度為:
B.37
C.44
D.46
16.將{5, 2, 7, 3, 4, 1, 6}依次插入初始為空的二叉搜索樹。則該樹的后序遍歷結果是:
B.1, 4, 2, 6, 3, 7, 5
C.1, 4, 3, 2, 6, 7, 5
D.5, 4, 3, 7, 6, 2, 1
17.在下述結論中,正確的是:
① 只有2個結點的樹的度為1;
② 二叉樹的度為2;
③ 二叉樹的左右子樹可任意交換;
④ 在最大堆(大頂堆)中,從根到任意其它結點的路徑上的鍵值一定是按非遞增有序排列的。
B.②④
C.①②③
D.②③④
18.若二叉搜索樹是有N個結點的完全二叉樹,則不正確的說法是:
B.最小值一定在葉結點上
C.最大值一定在葉結點上
D.中位值結點在根結點或根的左子樹上
19.將 { 10, 12, 1, 14, 6, 5, 8, 15, 3, 9, 7 } 逐個按順序插入到初始為空的最小堆中,然后連續執行兩次刪除最小元素操作(DeleteMin),再插入4,16,此后堆頂的元素是什么?
B.5
C.7
D.9
20.Insert {5, 2, 7, 3, 4, 1, 6} one by one into an initially empty min-heap. The preorder traversal sequence of the resulting tree is:
B.1, 2, 3, 4, 5, 7, 6
C.1, 2, 5, 3, 4, 7, 6
D.1, 3, 5, 4, 2, 7, 6
程序填空題
1.本題要求給出下列並查集操作執行后,集合數組內存儲的結果。
union( find(4), find(6) )
union( find(2), find(7) )
union( find(0), find(4) )
union( find(7), find(6) )
union( find(7), find(1) )
注意:這里假設按規模求並(若兩集合規模相等,則把第1個集合的根結點作為結果的根結點),並且用帶路徑壓縮的查找。對所有的0≤i≤7,S[i]
被初始化為−1。
i |
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
---|---|---|---|---|---|---|---|---|
S[i] |
4 | -1 | -1 | 4 |
2.請填空完成下列代碼,功能是實現並查集中的“查”,並且帶路徑壓縮。
SetType Find ( ElementType X, DisjSet S ) { ElementType root, trail, lead; for ( root = X; S[root] > 0; ) ; for ( trail = X; trail != root; trail = lead ) { lead = S[trail] ; ; } return root; } |