1.[10] Suppose we have 14 integers: 10, 100, 30, 130, 80, 50, 140, 20, 60, 70, 120, 40, 90, 110. Please create a 2-3 tree by inserting one integer at a time in the order shown. Please draw the resulting 2-3 tree after each insertion for the last five insertions. Ans: 1010, , , , , , , , , , 2050, , 140
30, , 2050, , , , Insert , , , 80 Insert , , , 130
Insert , 20 70, , , 50 Insert , , 20 40,
Insert , , 20 40, ,
2.[10] Suppose we have 14 integers: 10, 190, 100, 30, 130, 80, 180, 50, 140, 20, 200, 60, 160, 120. Please create a tree by inserting one integer at a time in the order shown. Please draw the resulting tree after each insertion for the last five insertions
3-1( 插入 100) 3.[10] Suppose we have 14 integers: 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140. Please create an AVL tree by inserting one integer at a time in the order shown. Please draw the resulting AVL tree after each insertion for the last five insertions.
3-2 ( 插入 110)
3-3 ( 插入 120)
3-4 ( 插入 130)
3-5 ( 插入 140)
4. [10] Suppose we have 14 integers: 10, 20, 30, 40, 50, 80, 100, 120, 130, 160, 180, 29, 48, 68. Please create a hash table of size 17, with linear probing and the hash function h(x) = x%17, by inserting one integer at a time in the order shown. Please draw the resulting hash table after each insertion for the last two insertions. 4-1( 紅色字代表插入的數字 ) 4-2( 紅色字代表插入的數字 )
5.[10] Suppose we have 14 integers: 10, 20, 30, 40, 50, 80, 100, 120, 130, 160, 180, 29, 48, 68. Please create a hash table of size 17, with double hashing and the hash functions h 1 (x) = x%17 and h 2 (x) = 7 – (x%7), by inserting one integer at a time in the order shown. Please draw the resulting hash table after each insertion for the last two insertions. 5-1( 紅色字代表插入的數字 ) 5-2( 紅色字代表插入的數字 )
6.[10] Suppose we have a 2-3 tree shown in Figure 1. Please answer the following questions: a)[2.5] Please insert 45 into Figure 1 and show the resulting 2-3 tree. Ans: 30, 35 37, , , 20 33, , 35 37, , , 45 10, 20 33,
b)[2.5] Please insert 15 into Figure 1 and show the resulting 2-3 tree. Ans: c)[2.5] Please insert 32 into Figure 1 and show the resulting 2-3 tree. Ans: 39 70, , , ,
d)[2.5] Please insert 25 into Figure 1 and show the resulting 2-3 tree. Ans: 39 70, ,
7.[10] Suppose we have a 2-3 tree shown in Figure 1. Please answer the following questions: a)[5] Please delete 34 from Figure 1 and show the resulting 2-3 tree. Ans: 30, 35 37, , , 20 33, , 35 37, , ,
b)[5] Please delete 50 from Figure 1 and show the resulting 2-3 tree. Note that a deleted node is replaced by the least number in its right subtree. Ans: 30, 35 37, , 20 33, , 80 36
8.[10] Suppose we have a tree shown in Figure 2. Please answer the following questions: [2.5] Please insert 45 into Figure 2 and show the resulting tree. [2.5] Please insert 18 into Figure 2 and show the resulting tree. [2.5] Please insert 31 into Figure 2 and show the resulting tree. [2.5] Please insert 16 into Figure 2 and show the resulting tree.
a
b
c
d
9.[10] Suppose we have a tree shown in Figure 2. Please answer the following questions: [5] Please delete 33 from Figure 2 and show the resulting tree. [5] Please delete 35 from Figure 2 and show the resulting tree. Note that a deleted node is replaced by the least number in its right subtree.
a
b
10.[10] Suppose we have an undirected graph shown in Figure 3. Please answer the following questions: [2.5] Please show the adjacency matrix for this graph (ignore the weights). [2.5] Please show the adjacency list for this graph (ignore the weights). Note that the nodes in a linked list should be alphabetically ordered. [2.5] Please find a minimum spanning tree for this graph starting from node a using the algorithm introduced in the class. Note that a node that is alphabetically smaller should be selected earlier. Hint: The addition of an edge should not cause a cycle. [2.5] Please using the breadth-first search algorithm to visit the graph starting from node a. Note that a node that is alphabetically smaller should be visited earlier. Please indicate the order of each node in the traversal.
abcdefghi a b c d e f g h i a.
b.
C. D. a b c d e f h g i a cbd h e f ig
11.[10] Suppose we have a directed graph shown in Figure 4. Please answer the following questions: [2] Please show the adjacency matrix for this graph (ignore the weights). [2] Please show the adjacency list for this graph (ignore the weights). Note that the nodes labeled with smaller numbers should appear earlier in a linked list. [6] Find the shortest distances from node 0 to all the other nodes using the algorithm introduced in the class. Note that the nodes labeled with smaller numbers should be selected earlier. A
B.
C Step Step Step Step Step Step Step Step Step Step