Given input {4371, 1323, 6173, 4199, 4344, 9679, 1989} and a hash function h(x) = x mod 10, show the resulting: a. Separate chaining hash table. b. Hash table using linear probing. c. Hash table using quadratic probing. d. Hash table with second hash function h2(x) = 7 (x mod 7).
Read moreTextbook Solutions for Data Structures and Algorithm Analysis in Java
Question
a. Implement the word puzzle program using the algorithm described at the endof the chapter.b. We can get a big speed increase by storing, in addition to each word W, all ofWs prefixes. (If one of Ws prefixes is another word in the dictionary, it is storedas a real word.) Although this may seem to increase the size of the hash tabledrastically, it does not, because many words have the same prefixes. When a scanis performed in a particular direction, if the word that is looked up is not evenin the hash table as a prefix, then the scan in that direction can be terminatedearly. Use this idea to write an improved program to solve the word puzzle.c. If we are willing to sacrifice the sanctity of the hash table ADT, we can speed upthe program in part (b) by noting that if, for example, we have just computedthe hash function for excel, we do not need to compute the hash function forexcels from scratch. Adjust your hash function so that it can take advantage ofits previous calculation.d. In Chapter 2, we suggested using binary search. Incorporate the idea of usingprefixes into your binary search algorithm. The modification should be simple.Which algorithm is faster? class Map2 {3 public Map( )45 public void put( KeyType key, ValueType val )6 public ValueType get( KeyType key )7 public boolean isEmpty( )8 public void makeEmpty( )910 private QuadraticProbingHashTable> items;1112 private static class Entry13 {14 KeyType key;15 ValueType value;16 // Appropriate Constructors, etc.17 }18 }
Solution
The first step in solving 5 problem number 18 trying to solve the problem we have to refer to the textbook question: a. Implement the word puzzle program using the algorithm described at the endof the chapter.b. We can get a big speed increase by storing, in addition to each word W, all ofWs prefixes. (If one of Ws prefixes is another word in the dictionary, it is storedas a real word.) Although this may seem to increase the size of the hash tabledrastically, it does not, because many words have the same prefixes. When a scanis performed in a particular direction, if the word that is looked up is not evenin the hash table as a prefix, then the scan in that direction can be terminatedearly. Use this idea to write an improved program to solve the word puzzle.c. If we are willing to sacrifice the sanctity of the hash table ADT, we can speed upthe program in part (b) by noting that if, for example, we have just computedthe hash function for excel, we do not need to compute the hash function forexcels from scratch. Adjust your hash function so that it can take advantage ofits previous calculation.d. In Chapter 2, we suggested using binary search. Incorporate the idea of usingprefixes into your binary search algorithm. The modification should be simple.Which algorithm is faster? class Map2 {3 public Map( )45 public void put( KeyType key, ValueType val )6 public ValueType get( KeyType key )7 public boolean isEmpty( )8 public void makeEmpty( )910 private QuadraticProbingHashTable> items;1112 private static class Entry13 {14 KeyType key;15 ValueType value;16 // Appropriate Constructors, etc.17 }18 }
From the textbook chapter Hashing you will find a few key concepts needed to solve this.
Visible to paid subscribers only
Step 3 of 7)Visible to paid subscribers only
full solution