Answered step by step
Verified Expert Solution
Question
1 Approved Answer
IN JAVA, implement the Map ADT based on Separate Chaining Hash Table., which is in Section 10.2.2. That means implementing all the 8 functions based
IN JAVA, implement the Map ADT based on Separate Chaining Hash Table., which is in Section 10.2.2. That means implementing all the 8 functions based on Separate Chaining Hash Table and run your codes on Example 10.1. Your program should print out that table in Example 10.1.
Since a map stores a collection of objects, it should be viewed as a collection of cey-value pairs. As an ADT, a map M supports the following methods: size( ): Returns the number of entries in M. isEmpty (): Returns a boolean indicating whether M is empty. get (k) : Returns the value v associated with key k, if such an entry exists; otherwise returns null. put(k,v) : If M does not have an entry with key equal to k, then adds entry (k,v) to M and returns null; else, replaces with v the existing value of the entry with key equal to k and returns the old value. remove (k) : Removes from M the entry with key equal to k, and returns its value; if M has no such entry, then returns null. keySet( ): Returns an iterable collection containing all the keys stored in M. values( ): Returns an iterable collection containing all the values of entries stored in M (with repetition if multiple keys map to the same value). entrySet(): Returns an iterable collection containing all the key-value entries in M. A simple and efficient way for dealing with collisions is to have each bucket A[j] store its own secondary container, holding all entries (k,v) such that h(k)=j. A natural choice for the secondary container is a small map instance implemented using an unordered list, as described in Section 10.1.4. This collision resolution rule is known as separate chaining, and is illustrated in Figure 10.6. Figure 10.6: A hash table of size 13, storing 10 entries with integer keys, with collisions resolved by separate chaining. The compression function is h(k)=kmod 13. For simplicity, we do not show the values associated with the keys. Example 10.1: In the following, we show the effect of a series of operations on an initially empty map storing entries with integer keys and single-character valuesStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started