Exercises from Chapter 9 9.3 9.9 9.13 9.14 9.16 Solutions 9.3 During interpolation i, the size of the jumps is n^(1/2^i). (I'm using a^b to mean a to the power b.) So the number of interpolations is the smallest number m such that n^(1/2^m) <= 1. Solving n^(1/2^m) <= 1 for m, m >= log log n. Since each interpolation costs on average O(1), the total average cost is O(log log n). 9.9 template void MoveTo Front(Elem A[]) { int n = 0; // GETNEXT is a function that returns the next item. // DONE is a user-defined value indicating end of items. while ((Elem val = GETNEXT()) != DONE) { for (i=0; i 0) { A[i] = A[i-1]; i--; } A[0] = val; } } 9.13 (a) NO: hash value will be greater than largest index in HT when k > n^2. (b) It would work correctly, but it is a very bad hash function because any two items will have a collision. (c) NO: a hash function must return the same value each time. (d) YES: In fact, this is often used in practice if not much is known about the distribution of key values. 9.14 Table index Value 0 1 2 9 3 3 4 2 5 12 6 Slots 0 and 1 each have probability 1/7 of being filled next. Slot 6 has probability 5/7 of being filled next. 9.16 Here are the two hash values for each item: Key H1 H2 2 2 3 8 8 9 31 5 1 20 7 1 19 6 2 18 5 3 53 1 1 27 1 5 This shows the probing that results from inserting each item: Key Slots probed (including initial slot) 2 2 8 8 31 5 20 7 19 6 18 5, 8, 11 53 1 27 1, 6, 11, 3 The final table is: Table index Value 0 1 53 2 2 3 27 4 5 31 6 19 7 20 8 8 9 10 11 18 12