advertisement

Q1. a)Suppose that a 500*500 matrix that has 2000 nonzero terms is to be represented. How much space is needed when a 500*500 two-dimensional array of type int is used? How much space is needed when sparseMatrix is used? b) How many nonzero elements must an m*n matrix have before the space required by sparseMatrix exceeds that required by an m*n two-dimensional array? You may assume that T is int. Q2. A three-dimensional m*n*p array has mnp elements. a)Determine the amount of memory used when these mnp elements are stored using a three-dimensional C++ array and when they are stored in a one-dimensional array using row-major mapping. Assume that the elements are of type int. First do this exercise for the case m = 10, n=4, and p=2 and then for general m, n, p. b)How large can the ratio of the two memory requirements get? Q3. You have a hash table with b buckets, the hash function is f(k) = k %b (D=b). Which of the following b values satisfies the recommendation made for the hash function divisor is Example 10.10? That is, the ideal choice for D is a prime number, when you cannot find a prime number close to the table length you have in mind, you should choose D so that it is not divisible by any number between 2 and 19. (a) b = 93 (b) b=37 (c) b = 1024 (d) b = 529 Q4. Linear Probing: The easiest way to find a place to put an 23 is to search the table for the next available bucket and put it in. This method of handling overflows is called linear probing. Use linear probing, a hash table with b = 13 buckets, and the hash function f(k) = k%b. Start with an empty hash table and insert pairs whose keys are 7, 42, 25, 70, 14, 38, 8, 21, 34, 11 (a) Draw the hash table following each insert. (b) What is the loading factor of your table after last insert. (c) What’s the maximum and average number of buckets examined in a unsuccessful search of your table. (d) What’s a maximum and average number of buckets examined in a successful search. (e)Compute U_n and S_n using your loading factor and the formulas for linear probing. How do these numbers compare with the numbers you computed in part (c) (d), explain any discrepancy. Q5. Determine a suitable value for the hash function divisor D when linear probing is used. Do this for each of the following situation. a) n = 50, S_n <= 3, U_n <= 20 b) n=500, S_n <=5 U_n <= 60 c) n= 10, S_n <=2, U_n <=10 Q6. Delete for buckets using Linear Probing f(k) = k%13 Key table [] 25 26 15 0 1 2 28 4 3 4 36 19 5 6 7 8 9 23 24 12 10 11 12 What the table will look like after deleting element 24?