Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 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, 100 30 10 100 30 10 100, 130 30, 100 10 80 130 30, 100 1050, 80 130 30, 100 10 50, 80 130, 140 30, 100 10, 2050, 80 130, 140

2 30, 100 10, 2050, 80 130, 140 60 30 100 10, 20 130, 140 50 80 Insert 70 60 30 100 10, 20 130, 140 50 70, 80 Insert 120 60 30 10, 20 50 70, 80 120 140 100, 130

3 Insert 40 60 30 10, 20 70, 80 120 140 100, 130 40, 50 Insert 90 30 60, 100 80 130 7090 10, 20 40, 50 120 140

4 Insert 110 30 60, 100 80 130 7090 10, 20 40, 50 110, 120 140

5 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. 1010 19010 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 190 50 80

6 30 100 180 10 20 190 50 80 130 140 30 100 180 10 20 190 200 50 80 130 140 30 100 180 10 20 190 200 50 60 80 130 140

7 30 100 180 10 20 190 200 50 60 80 130 140 160 100 30 140 180 10 20 50 60 80 120 130190 200 160

8 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.

9 3-2 ( 插入 110)

10 3-3 ( 插入 120)

11 3-4 ( 插入 130)

12 3-5 ( 插入 140)

13 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( 紅色字代表插入的數字 )

14 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( 紅色字代表插入的數字 )

15 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 3840 10, 20 33, 34 100 60 80 36 30, 35 37, 50 39 70, 90 3840, 45 10, 20 33, 34 100 60 80 36

16 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 3840 33, 34 100 60 80 36 37 3050 15 35 10 20 39 70, 90 3840 100 60 80 36 37 3350 30 35 10, 20 32 34

17 d)[2.5] Please insert 25 into Figure 1 and show the resulting 2-3 tree. Ans: 39 70, 90 3840 33, 34 100 60 80 36 37 3050 20 35 10 25

18 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 3840 10, 20 33, 34 100 60 80 36 30, 35 37, 50 39 70, 90 3840 10, 20 33 100 60 80 36

19 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 3840 10, 20 33, 34 100 70, 80 36

20 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.

21 37 50 70 90 39 38 60 80 100 40 45 a 30 35 10 15 20 32 33 34 36

22 37 50 70 90 39 38 60 80 100 40 b 15 30 35 18 20 36 10 32 33 34

23 37 50 70 90 39 38 60 80 100 40 c 30 33 35 31 32 36 10 15 20 34

24 37 50 70 90 39 38 60 80 100 40 d 15 30 35 16 20 36 10 32 33 34

25 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.

26 37 50 70 90 39 38 60 80 100 40 a 30 35 10 15 20 32 34 36

27 37 50 70 90 39 38 60 80 100 40 b 30 34 10 15 20 32 33 36

28 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.

29 abcdefghi a011100000 b101000000 c110110000 d101001010 e001001101 f000110100 g000011000 h000100000 i000010000 a.

30 b.

31 C. D. a b c d e f h g i a cbd h e f ig

32 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. 0123456 00111000 10010100 20001100 30010110 40010011 50000100 60000010

33 B.

34 C. 0123456 Step 100246 Step 20 102465 Step 30 1 202465 Step 40 1 2 402465106 Step 50 1 2 4 30246596 Step 60 1 2 4 3 60246586 Step 70 1 2 4 3 6 50246586 Step 50 1 2 4 60246586 Step 60 1 2 4 6 30246586 Step 70 1 2 4 3 6 50246586


Download ppt "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."

Similar presentations


Ads by Google