write a method contains() that returns true if the key is stored in the array values. the key is stored using closed hashing with linear probing method and uses keytoindex() as the hash function. (keytoindex() is already defined and provided for you). linear probing means that when we have a collision, we check the next (hence linear) position to see if the key is there (probing). we continue until we find they key or find an empty slot (null) in values. The details of the algorithm are:
Compute the index for the key by calling keyToIndex().
If position index in values is empty (i.e. null) then the key is not found and we return false.
If position index is in use (i.e., not null) then we compare the key with the value stored at index. If they are the same, then the key exists and we return true.
Otherwise, the position index is in use and the key stored there is not the same as the key being searched. This is a collision and we must resolve it using linear probing. Increment the index returned by keyToIndex() by one and check the next position. Continue doing this until either you find a position with the key already stored (return true) or you find an empty position (return false). When you increment index, make sure you wrap it around the end of the values table using the remainder (modulo) so that you check all possible positions.
boolean contains(String key, String values[])
{
int index = keyToIndex(key);
<< your code here >>

Respuesta :

Boolean includes (String key, String values[]) <your code here>: int index = keyToIndex(key);.

A technique called hashing is used to distinguish one particular object from a collection of related ones. Let's say a key is given to an item to make searching easier. One can use a straightforward array akin to a data structure to store the key/value combination, where keys (integers) can be used directly as an index to store values.

Hashing should be employed, nevertheless, when the keys are big and cannot be utilized as an index directly. During hashing, hash functions are used to break up huge keys into smaller ones. The values are then kept in a hash table, a type of data structure. Using linear probing the hashing method might be used to produce an array index that has already been used. If this is the case, we can look into each subsequent cell in the array until we discover one that is empty. This method is known as linear probing.

To know more about hashing click here:

https://brainly.com/question/13106914

#SPJ4