10, 100
DESCRIPTION
[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 : . 3 0. 3 0. 10, 100. - PowerPoint PPT PresentationTRANSCRIPT
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:
10 10, 100
30
10 100
30
10 100, 130
30, 100
10 80 130
30, 100
10 50, 80 130
30, 100
10 50, 80 130, 140
30, 100
10, 20 50, 80 130, 140
30, 100
10, 20 50, 80 130, 140
60
30 100
10, 20 130, 14050 80
Insert 70
60
30 100
10, 20 130, 14050 70, 80
Insert 120
60
30
10, 20 50 70, 80 120 140
100, 130
Insert 40
60
30
10, 20 70, 80 120 140
100, 130
40, 50
Insert 90 30
60, 100
80 130
70 9010, 20 40, 50 120 140
Insert 110 30
60, 100
80 130
70 9010, 20 40, 50 110, 120 140
2.[10] Suppose we have 14 integers: 10, 190, 100, 30, 130, 80, 180, 50, 140, 20, 200, 60, 160, 120. Please create a 2-3-4 tree by inserting one integer at a
time in the order shown. Please draw the resulting 2-3-4 tree after each insertion for the last five insertions.
10 10 190 10 100 190
100
10 30 190
100
10 30 130 190
100
10 30 80 130 190
100
10 30 80 130 180 190
30 100
10 130 180 19050 80
30 100 180
10 20 19050 80 130 140
30 100 180
10 20 190 20050 80 130 140
30 100 180
10 20 190 20050 60 80 130 140
30 100 180
10 20 190 20050 60 80 130 140 160
100
30 140 180
10 20 50 60 80 120 130 190 200160
40
20 80
10 30 60 90
50 70 100
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)
40
20 80
10 30 60 100
50 70 11090
3-3 (插入 120)
80
40 100
20 60 90 110
10 50 12030 70
3-4 (插入 130)
80
40 100
20 60 90 120
10 50 13030 70 110
3-5 (插入 140)
80
40 120
20 60 100 130
10 50 11030 70 90 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(紅色字代表插入的數字 )
Index Value0 291 1202 483 20456 407 1608910 1011 13012 8013 3014 18015 10016 50
Index Value0 291 1202 483 204 6856 407 1608910 1011 13012 8013 3014 18015 10016 50
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 h1(x) = x%17 and h2(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(紅色字代表插入的數字 )
Index Value0 481 1202 293 20456 407 1608910 1011 13012 8013 3014 18015 10016 50
Index Value0 481 1202 293 204 6856 407 1608910 1011 13012 8013 3014 18015 10016 50
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, 50
39 70, 90
38 4010, 20 33, 34 10060 8036
30, 35
37, 50
39 70, 90
38 40, 4510, 20 33, 34 10060 8036
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, 90
38 4033, 34 10060 8036
37
30 50
15 35
10 20
39 70, 90
38 40 10060 8036
37
33 50
30 35
10, 20 32 34
d) [2.5] Please insert 25 into Figure 1 and show the resulting 2-3 tree. Ans:
39 70, 90
38 4033, 34 10060 8036
37
30 50
20 35
10 25
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, 50
39 70, 90
38 4010, 20 33, 34 10060 8036
30, 35
37, 50
39 70, 90
38 4010, 20 33 10060 8036
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, 60
39 90
38 4010, 20 33, 34 10070, 8036
8.[10] Suppose we have a 2-3-4 tree shown in Figure 2. Please answer the following questions:
[2.5] Please insert 45 into Figure 2 and show the resulting 2-3-4 tree.[2.5] Please insert 18 into Figure 2 and show the resulting 2-3-4 tree.[2.5] Please insert 31 into Figure 2 and show the resulting 2-3-4 tree.[2.5] Please insert 16 into Figure 2 and show the resulting 2-3-4 tree.
37 50
70 90
39
3860 80 100
40 45
a
30 35
10 15 20
32 33 34
36
37 50
70 90
39
3860 80 100
40
b
15 30 35
18 2036
10
32 33 34
37 50
70 90
39
3860 80 100
40
c
30 33 35
31 32 36
10 15 20
34
37 50
70 90
39
3860 80 100
40
d
15 30 35
16 2036
10
32 33 34
9.[10] Suppose we have a 2-3-4 tree shown in Figure 2. Please answer the following questions:[5] Please delete 33 from Figure 2 and show the resulting 2-3-4 tree.
[5] Please delete 35 from Figure 2 and show the resulting 2-3-4 tree. Note that a deleted node is replaced by the least number in its right subtree.
37 50
70 90
39
3860 80 100
40
a
30 35
10 15 20
32 34
36
37 50
70 90
39
3860 80 100
40
b
30 34
10 15 20
32 33
36
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.
a b c d e f g h i
a 0 1 1 1 0 0 0 0 0
b 1 0 1 0 0 0 0 0 0
c 1 1 0 1 1 0 0 0 0
d 1 0 1 0 0 1 0 1 0
e 0 0 1 0 0 1 1 0 1
f 0 0 0 1 1 0 1 0 0
g 0 0 0 0 1 1 0 0 0
h 0 0 0 1 0 0 0 0 0
i 0 0 0 0 1 0 0 0 0
a.
• b.
• C.
• D. a b c d e f h g i
a
cb d
h
e f
i g
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.0 1 2 3 4 5 6
0 0 1 1 1 0 0 0
1 0 0 1 0 1 0 0
2 0 0 0 1 1 0 0
3 0 0 1 0 1 1 0
4 0 0 1 0 0 1 1
5 0 0 0 0 1 0 0
6 0 0 0 0 0 1 0
• B.
• C.0 1 2 3 4 5 6
Step 1 0 0 2 4 6
Step 2 0 1 0 2 4 6 5
Step 3 0 1 2 0 2 4 6 5
Step 4 0 1 2 4 0 2 4 6 5 10 6
Step 5 0 1 2 4 3 0 2 4 6 5 9 6
Step 6 0 1 2 4 3 6 0 2 4 6 5 8 6
Step 7 0 1 2 4 3 6 5 0 2 4 6 5 8 6
Step 5 0 1 2 4 6 0 2 4 6 5 8 6
Step 6 0 1 2 4 6 3 0 2 4 6 5 8 6
Step 7 0 1 2 4 3 6 5 0 2 4 6 5 8 6