1 / 17

Data Structures -3 rd exam-

Data Structures -3 rd exam-. 授課教授:李錫智.

andren
Télécharger la présentation

Data Structures -3 rd exam-

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. Data Structures-3rd exam- 授課教授:李錫智

  2. [5] Refer to the two trees in Fig. 1. Let’s define the balance factor BF of a node to be the absolute value of the difference between the heights of the children of the node. Please show the BF of each node in both trees. Are they AVL trees? Why or why not? Ans: AVL Tree  BF≦1 (a) 符合條件,所以(a)是AVL Tree (b)62的BF=2,所以不是AVL Tree (a) (b)

  3. [10] Consider ten integers 42, 22, 32, 74, 47, 52, 94, 29, 40, 58 in order. Using the hash function h(k) = k%11, construct an 11-element hash table with chaining for collision resolution. Draw the final hash table. Note that singly linked lists are used. An integer is inserted as the first node of a list. Ans:

  4. [10] Consider ten integers 42, 22, 32, 74, 47, 52, 94, 29, 40, 58 in order. Using the hash function h(k) = k%11, construct an 11-element hash table with linear probing for collision resolution. Draw the final hash table. Ans:

  5. [10] Consider the integers 42, 3, 17, 22, 32, 7, 12, 74, 47, 8, 5, 52, 94, 29, 15, 6, 40, 58 in order. Create a binary search tree for them and draw the final tree. Ans:

  6. [5] Please delete 17 from the binary search tree of Problem 4 and show the resulting binary search tree. Note that the right subtree is considered if necessary. Ans:

  7. [10] Consider the integers 42, 22, 32, 74, 47, 52, 94, 29, 40, 58 in order. Using the first hash function h(k) = k%11 and the secondary hash function d(k) = 5 – k%5, construct an 11-element hash table with double hashing for collision resolution. Draw the final hash table. Ans: (i+ jd(k)) mod N for j= 0, 1, … , N - 1 h(42)=9 h(22)=0 h(32)=10 h(74)=8 h(47)=3 h(52)=8 , d(52)=3 (8+1*3) mod 11=0 (8+2*3) mod 11=3 (8+3*3) mod 11=6 ……

  8. [10] Consider the integers 42, 3, 17, 22, 32, 7, 12, 74, 47, 8, 5, 52 in order. Create an AVL tree for them and draw the final tree. Also, draw the intermediate tree after each violation is resolved. Ans

  9. [10] 42, 3, 17, 22, 32, 7, 12, 74, 47, 8, 5, 52 Ans:

  10. [10] 42, 3, 17, 22, 32, 7, 12, 74, 47, 8, 5, 52 Ans:

  11. [5] Please delete 74 first and then delete 52 from the AVL tree of Problem 7 and show the resulting AVL tree. Note that the right subtree is considered if necessary. Ans:

  12. [10] Consider the integers 42, 3, 17, 22, 32, 7, 12, 74, 47, 8, 5 in order. Create a (2,4) tree for them and draw the final tree. Also, draw the intermediate tree after each violation is resolved. When an overflow occurs, please navigate the third number. Ans:

  13. [10] 42, 3, 17, 22, 32, 7, 12, 74, 47, 8, 5 Ans:

  14. [5] Please delete 47 from the (2,4) tree of Problem 9 and show the resulting (2,4) tree. Note that the right subtree is considered if necessary. Ans:

  15. [10] Consider an array A containing the integers 42, 3, 17, 22, 32, 7, 12, 74, 47, 8. Please sort the integers in ascending order using in-place quick-sort. Note that the first element of the underlying sequence is used as the pivot. Draw the array after the execution of each partition. Ans:

  16. [10] Consider an array A containing the integers 42, 3, 17, 22, 32, 7, 12, 74, 47, 8. Please sort the integers in ascending order using in-place quick-sort. Note that the first element of the underlying sequence is used as the pivot. Draw the array after the execution of each partition. Ans:

  17. [10(送分)] You are given a set S of n real numbers and another real number x. Describe a O(nlogn)-time algorithm that determines whether or not there exist two elements in S whose sum is exactly x. Ans:A set Sof n real numbers Real number x Algorithm judge (S, x) QuickSort(S); for i0 to n-1 do temp=x-S[i]; if (BinarySearch(temp)) return TRUE; return FALSE;

More Related