We need to store roughly 100000 names for fast, random retrieval. Below are some code segments and functions that define the table and provide insert and searching operations in unchained hash table. Collisions are resolved with linear probing. Fill in the blanks appropriately. Answer the questions at the bottom too. public static final int HTABLE_SIZE = ; //need decent size //for performance but not use too much space String name; //hold the current name String name Tab[HTABLE_SIZE]; //the hash table public int hash(String name) {//add up the unicodes of the characters of the name int key = 0; for(j=0; j< ; j++) key = key + .charAt( ; // weight letter by position return (key % ); } public int search(String name) //POST: returns position in hashtable where name should be located { int index = hash ); while (nameTab[index] != null && nameTab[index]. (name)!=0) { index = (index + ) % } return ; //note the slot is null if search fails
public boolean insert(String name) //POST: insert the string into the hash table and return true; //return false if already there { //inserts name into table int index; // where it is or where it should go index = search(name); // using the search to locate position if (name Tab[index]!=null){ // then already there return } else { // can insert instead name Tab[ ] = return } } What kind of hash function is in use? . What is the load factor for this and most hash tables?
The options for the boxes are 100000, 120000, 250000, 1, true, false, name.len(), HTABLE_SIZE, key, j, index, compareTo
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
The options for the boxes are 100000, 120000, 250000, 1, true, false, name.len(), HTABLE_SIZE, key, j, index, compareTo
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!