a. Implement the word puzzle program using the algorithm described at the endof the | StudySoup

Textbook Solutions for Data Structures and Algorithm Analysis in Java

Chapter 5 Problem 5.18

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

Step 1 of 7)

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.

Step 2 of 7)

Visible to paid subscribers only

Step 3 of 7)

Visible to paid subscribers only

Subscribe to view the
full solution

Title Data Structures and Algorithm Analysis in Java 3 
Author Mark A. Weiss
ISBN 9780132576277

a. Implement the word puzzle program using the algorithm described at the endof the

Chapter 5 textbook questions

×

Login

Organize all study tools for free

Or continue with
×

Register

Sign up for access to all content on our site!

Or continue with

Or login if you already have an account

×

Reset password

If you have an active account we’ll send you an e-mail for password recovery

Or login if you have your password back