1 / 34

10, 100

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

lilli
Télécharger la présentation

10, 100

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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: 30 30 10, 100 10 10 100, 130 10 100 30, 100 30, 100 10 80 10 50, 80 130 130 30, 100 30, 100 10, 20 50, 80 130, 140 50, 80 10 130, 140

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

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

  4. 60, 100 30 80 130 Insert 110 70 90 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. 10 10 190 10 100 190 100 100 100 190 130 190 10 30 130 190 10 30 80 10 30 100 30 100 130 180 190 10 30 80 10 130 180 190 50 80

  6. 30 100 180 10 20 130 140 190 50 80 30 100 180 10 20 130 140 190 200 50 80 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 140 180 30 160 50 60 80 10 20 120 130 190 200

  8. 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-1(插入100) 40 20 80 10 30 60 90 100 50 70

  9. 3-2 (插入110) 40 20 80 10 30 60 100 50 70 90 110

  10. 3-3 (插入120) 80 40 100 20 60 90 110 120 10 30 50 70

  11. 3-4 (插入130) 80 40 100 20 60 90 120 130 10 30 50 70 110

  12. 3-5 (插入140) 80 40 120 20 60 100 130 110 10 30 50 70 90 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 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(紅色字代表插入的數字)

  15. [10] Suppose we have a 2-3 tree shown in Figure 1. Please answer the following questions: • [2.5] Please insert 45 into Figure 1 and show the resulting 2-3 tree. Ans: 37, 50 30, 35 70, 90 39 36 10, 20 33, 34 38 40 60 100 80 37, 50 30, 35 70, 90 39 36 10, 20 33, 34 38 40, 45 60 100 80

  16. [2.5] Please insert 15 into Figure 1 and show the resulting 2-3 tree. Ans: • [2.5] Please insert 32 into Figure 1 and show the resulting 2-3 tree. Ans: 37 30 50 15 39 70, 90 35 36 10 60 100 80 20 33, 34 38 40 37 33 50 30 39 70, 90 35 36 10, 20 34 60 100 80 32 38 40

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

  18. [10] Suppose we have a 2-3 tree shown in Figure 1. Please answer the following questions: • [5] Please delete 34 from Figure 1 and show the resulting 2-3 tree. Ans: 37, 50 30, 35 70, 90 39 36 10, 20 33, 34 38 40 60 100 80 37, 50 30, 35 70, 90 39 36 10, 20 33 38 40 60 100 80

  19. [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: 37, 60 30, 35 90 39 36 10, 20 33, 34 38 40 70, 80 100

  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. a 37 50 70 90 30 35 39 60 100 80 38 40 45 36 10 15 20 32 33 34

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

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

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

  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. a 37 50 70 90 30 35 39 60 100 80 38 40 36 10 15 20 32 34

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

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

  30. b.

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

  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.

  33. B.

  34. C.

More Related