Dept. of Computer Science and Information Engineering, National Dong Hwa University Data Structures â€“ Final Exam, Jan. 10, 2011 1. (10%) Find the shortest path from A to H in the following directed network (its edges with weights are shown below). AB 14 ; AC 5 ; AE 7 ; BD 4 ; CB 13 ; CF 16 ; DF 3 ; DH 18 ; EB 6 ; FH 11 2. (10%) Construct Huffman binary code for eight characters whose probabilities of appearance are A: 0.15, B: 0.19, C:0.23, D:0.04, E:0.11, F:0.08, G:0.14 and H: 0.06. What is the average number of bits per character? 3. (25%) Fill the following table of sorting n elements with various algorithms. Determine the time and space complexity with Big-Oh and whether it is stable or unstable. Time Best case

Worst case

Space Average case

Stable/ Unstable

Insertion Sort Selection Sort Quick Sort Merge Sort Heap sort 4. (10%) Given the sequence of numbers: 8, 1, 7, 2, 6, 3, 5, 4 we intend to sort them into ascending order. a. How many swaps does it take to sort this sequence via Insertion sort? b. How many recursive calls does it take by the Merge sort to get the job done? 5. (10%) Demonstrate the insertion of the keys 5, 28, 19, 15, 20, 33, 12, 17, 10 into a hash table which collisions resolved by chaining. Let the table have 9 slots, and let the hash function be h(k) = k mod 9. 6.

(10%) An unsorted sequence 26, 5, 77, 1, 61, 11, 59, 15, 48, 19 is stored in an array and to be sorted in increasing order. Write the contents of the array in the first two passes of heap sort.

7. (15%) Assume that the data and key are both integers. The hash table size(HSize) is 10. The index runs from 0 to 9. Please fill in the content of the hash table if numbers 6, 3, 35, 15, 27, 95, and 23 are swquentially inserted into the hash table using the following scheme. If a number can be inserted to hash table, please indicate it. a. Hash Function: key mod HSize, open addressing with linear probing. 0 1 2 3 4 5 6 7 8

9

b. HF: key mod HSize, open addressing with quadratic probing. (use HF’ if HF is overflow). HF’: (key 0

) mod HSize , i = 1, 2, 3, … 1

2

3

4

5

6

7

8

9

c. Some numbers may not be able to insert to the table even though there are still spaces in the hash table for quadratic probing or double hashing. What can we do to reduce the chance of this mishap to happen when we design the hash table. 8.

(10%) Compute the lengths of all-pair shortest paths for the directed graph of 5 vertices represented by the following matrix such that each entry =t represents that there is an edge directed from vertex i to vertex j with weight t.