Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "授課教授:李錫智 Data Structures -3 rd exam-. 1.[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."— Presentation transcript:

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

2 1.[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 2.[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 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 linear probing for collision resolution. Draw the final hash table. Ans:

5 4.[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.[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 6.[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 7.[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 7.[10] 42, 3, 17, 22, 32, 7, 12, 74, 47, 8, 5, 52 Ans:

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

11 8.[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 9.[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 9.[10] 42, 3, 17, 22, 32, 7, 12, 74, 47, 8, 5 Ans:

14 10.[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 11.[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 11.[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 12.[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 S of 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;


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

Similar presentations


Ads by Google